Problem1014--Which level has most nodes

1014: Which level has most nodes

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Given a tree, we want to know which level has maximum number of nodes. if there are more than one level, then output all of them in ascending order!
The node R is root and it is level 1.

Input

The first line contains two integer which is N and R, N is the number of nodes and R is the root. 
In the following N lines, each line has two integer x and y which means there is an edge between node x and node y.
( 1<= x, y <= N )
The input is guaranteed a tree !  ( 1<= N <= 100 )

Output

one line contains some integers in ascending order; they are the levels with most nodes in the tree

Sample Input Copy

7 2 
1 3
2 3
2 4
4 5
3 6
2 7

Sample Output Copy

3 2 3

HINT

In the example output: 3 2 3 ; the maximum number of nodes is 3 (the first 3); they are in level 2 and level 3 (the second 3)

Source/Category