#K48337. Tree Depths

    ID: 28398 Type: Default 1000ms 256MiB

Tree Depths

Tree Depths

Given a tree with n nodes labeled 1 through n and n-1 edges, rooted at node 1, your task is to compute the depth of each node. The depth of a node is defined as the number of edges in the unique path from the root (node 1) to that node.

The depth of a node \( u \) is given by the formula: \[ \text{depth}(u) = \text{number of edges from node } 1 \text{ to node } u \]

You are required to read the input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

The first line contains a single integer \( n \) representing the number of nodes. The next \( n-1 \) lines each contain two integers \( u \) and \( v \) indicating there is an edge between node \( u \) and node \( v \). The tree is rooted at node 1.

outputFormat

Output a single line containing \( n \) integers separated by spaces. The \( i \)-th integer represents the depth of node \( i \), where the depth of the root is 0.

## sample
5
1 2
1 3
3 4
3 5
0 1 1 2 2

</p>