#P8655. [蓝桥杯 2017 国 B] 发现环
[蓝桥杯 2017 国 B] 发现环
Description
Xiaoming's lab has computers, numbered . Originally, there were data links connecting these computers, forming a tree network. In a tree network, there is a unique path between any two computers.
However, during a recent network maintenance, the administrator made a mistake and added one extra data link between two computers, so a cycle appeared in the network. For the computers on the cycle, since there is no longer only one path between each pair of them, data transmission on these computers has bugs.
To restore normal transmission, Xiaoming needs to find all computers that are on the cycle. Can you help him?
Input Format
The first line contains an integer .
The following lines each contain two integers and , indicating that there is a data link between and .
The input is guaranteed to be valid.
Output Format
Output the numbers of the computers on the cycle in increasing order, separated by a single space.
5
1 2
3 1
2 4
2 5
5 3
1 2 3 5
Hint
For of the testdata, .
For of the testdata, , .
Time limit: 1 second, 256 MB. Lanqiao Cup 2017, the 8th National Contest.
Translated by ChatGPT 5
京公网安备 11011102002149号