#P2999. Chocolate Milk Insertion

    ID: 16257 Type: Default 1000ms 256MiB

Chocolate Milk Insertion

Chocolate Milk Insertion

Farmer John's milk production system is arranged as a tree with N nodes and N-1 pipes. Each pipe is a directed edge from node Ai to node Bi (with Ai < Bi). A node with no incoming pipe is a milking machine and a node with no outgoing pipe is a milk tank. All milk flows from some milking machine to a milk tank along the unique simple path that exists between any two nodes. Due to the layout, there is at most one way for milk to flow from one joint to any other joint, and every pipe is used.

Farmer John wants to install a single chocolate inserter at a joint (i.e. a node that is not a milking machine) such that all milk produced passes through that joint. In other words, if we denote the set of milking machines as S and the set of tanks as T, then a joint j is a valid installation point if for every source s ∈ S and every tank t ∈ T, the unique path from s to t passes through j.

Your task is to assist Farmer John in finding all such nodes where he can install his chocolate inserter.

Note: You cannot install the chocolate inserter at the same location as a milking machine.

inputFormat

The first line contains an integer N (2 ≤ N ≤ 100,000) representing the number of nodes. The next N-1 lines each contain two integers Ai and Bi (1 ≤ Ai < Bi ≤ N) indicating that milk flows from node Ai to node Bi.

outputFormat

Output in a single line all the candidate node numbers (in increasing order, separated by spaces) where the chocolate inserter can be installed.

sample

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