Problem D
Busiest Ant Level
Deep under the forest, an ant colony is built as a network of tunnels and chambers. It is possible to reach every chamber from every chamber using a unique path. Chamber $0$ is the queen’s chamber and is at level $0$. The level of a chamber is its distance from the queen’s chamber, counted in terms of how many tunnels must be taken to reach it from the queen’s chamber.
Your task: find the level that contains the most chambers. If multiple levels have the same maximum number of chambers, print the lowest-numbered level.
Input
The first line contains one integer $n$ ($1 \le n \le 100\, 000$), which stands for the number of chambers in the ant colony.
The next $n-1$ lines each contain two integers $u$ and $v$ ($0 \leq u, v < n$) meaning there is a tunnel between chambers $u$ and $v$.
Output
The level that contains the maximum number of chambers. If there is a tie, print the smallest such level.
| Sample Input 1 | Sample Output 1 |
|---|---|
3 0 1 0 2 |
1 |
| Sample Input 2 | Sample Output 2 |
|---|---|
16 0 1 0 2 0 3 1 4 1 5 2 6 2 7 3 8 3 9 4 10 5 11 5 12 8 13 8 14 8 15 |
2 |
