Mykola, Vasyl and a maze
Limits: 2 sec., 256 MiB
The Office of «Extralogic» is a real maze. Builders Vasyl and Mykola do not only can’t find a room, they have to paint the door, and got lost!
In order to somehow help the poor builders, the kind employees of «Extralogic» handed an office plan to Mykola and Vasyl. According to the plan, the office consists of nn rooms, some of which are connected by a passage. There are nn such passages. Each passage is bidirectional. It is guaranteed that there is a path between any pair of rooms in the office, and that there is no more than one passage between any pair of rooms in the office.
Mykola and Vasyl remember that they had to draw a door to one of the rooms, which is located in a cycle. A cycle is a sequence of different office rooms a1,a2,...,aka1,a2,...,ak, that includes a passage between rooms a1a1 and a2a2, a2a2 and a3a3, ..., ak−1ak−1 and akak, akak and a1a1. Help builders find lists of all office rooms that belong in at least one cycle.
Input
First line contains one integer nn – number of rooms in the ofice.
Next nn lines contain two integers aiai and bibi – describes ii-th passage between rooms aiai and bibi.
Output
In first line print one integer kk – number of rooms which belongs to at least one cycle.
In second line print kk integers – indecies of rooms in ascening order.
Constraints
30%30% tests: 3≤n≤1003≤n≤100.
70%70% tests: 3≤n≤1053≤n≤105.
For all tests: 1≤ai,bi≤n1≤ai,bi≤n.
Samples
Input (stdin) | Output (stdout) |
---|---|
4 1 2 2 3 3 4 4 2 | 3 2 3 4 |
Notes
Rooms 2, 3 and 4 belong to a cycle. Room 1 does not belong to any cycle.