#Q161. 「一本通 5.2 练习 2」旅游规划

「一本通 5.2 练习 2」旅游规划

Description

The traffic planning in City W has encountered a major issue. The city government is determined to deploy traffic coordinators at major intersections to manage the dense flow of vehicles. However, due to a shortage of personnel, the mayor of City W has decided to assign coordinators only to the intersections that are most in need.

Specifically, City W's traffic network is quite simple, consisting of nn intersections and n1n-1 streets, with intersections numbered sequentially from 00 to n1n-1. Each street connects two intersections, and there is exactly one path between any two intersections.

After a long-term investigation, the results show that if an intersection lies on the longest path in City W's traffic network, it is bound to be extremely congested. The longest path is defined as a path p=(v1,v2,v3,,vk)p=(v_1,v_2,v_3,\cdots,v_k) where all intersections on the path are distinct, and there exists no path in the city with a length greater than kk. Note that the longest path may not be unique. Therefore, the mayor of City W wants to know which intersections are located on the longest paths of the city's traffic network.

Input Format

The first line contains an integer nn;

The following n1n-1 lines each contain two integers uu and vv, indicating that there is a street between intersections uu and vv.

Output Format

The output consists of several lines, each containing an integer—the number of an intersection located on the longest path. To ensure the solution is unique, please output all intersection numbers on the longest paths in ascending order.

Sample 1

10
0 1
0 2
0 4
0 6
0 7
1 3
2 5
4 8
6 9

0
1
2
3
4
5
6
8
9

Data Range and Hint

For all data, 1n2×1051\le n\le 2\times 10^5.