Problem list
Log in
#r03342 · Online Judge > GoldOJ

Tree Parent and Depth

Silver II 2.0 s 256 MB

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
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code