AdvancedRating 2000
Sum of Distances From Every Node
For every node, print the sum of its distances (in edges) to all other nodes of the tree.
Input
n; then n − 1 lines 'u v'.
Output
n integers (for nodes 1 … n).
Sample 1
Input
6 1 2 1 3 3 4 3 5 3 6
Output
8 12 6 10 10 10
Sample 2
Input
1
Output
0
Output appears here