Given a tree on $N$ nodes rooted at node $1$, print for each node $1..N$ its parent's number and its depth (edges from the root; the root has depth $0$). The root prints parent $0$.
Input
First line $N$ ($1 \le N \le 100000$); then $N-1$ undirected edge lines $u$, $v$ ($u \ne v$).
Output
Print $N$ lines; line $i$ is node $i$'s parent and depth.
Example 1
Input
6 1 2 1 3 2 4 2 5 4 6
Output
0 0 1 1 1 1 2 2 2 2 4 3
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.