Finding Parents in a Tree

Starting from node 1 as the root, print the parent of every other node in the given tree.

Easy3BFSTreeInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

A tree with no designated root is given. Take node 1 as the root, then find the parent of every node other than node 1.

The parent of a node is the node that comes immediately before it on the path from the root to that node.

Input

The first line contains the number of nodes NN (2N1000002 \le N \le 100\,000). The nodes are numbered from 1 to NN.

Each of the next N1N-1 lines contains the numbers of two nodes joined by an edge, separated by a space. The given graph is always a tree.

Output

Print N1N-1 lines. Print the parent of each node, one per line, in order from node 2 to node NN.