#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 intersections and streets, with intersections numbered sequentially from to . 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 where all intersections on the path are distinct, and there exists no path in the city with a length greater than . 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 ;
The following lines each contain two integers and , indicating that there is a street between intersections and .
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, .