Problem10401--树的中心 I

10401: 树的中心 I

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

给定一棵树,树中包含 $n$ 个结点(编号 $1\sim n$)和 $n-1$ 条无向边。
输出每个结点到叶子的最远距离。本题规定根节点的深度为 $0$。

Input

第一行包含整数 $n\ (1≤n≤50,000)$。
接下来 $n−1$ 行,每行包含三个整数 $a_i,b_i$,表示点 $a_i$ 和 $b_i$ 之间存在一条边。

Output

输出共 $n$ 行。
第 $i$ 行,表示以 $i$ 为根节点,到叶子的最远距离。

Sample 1 Input

7
1 2
2 3
2 4
1 5
5 6
6 7

Sample 1 Output

3
4
5
5
3
4
5
以 1 为根节点对应的树为

以 2 为根节点对应的树为

以此类推。

Sample 2 Input

5 
2 1
3 2
4 3
5 1

Sample 2 Output

3
2
3
4
4

Sample 3 Input

10
2 1
3 1
4 3
5 3
6 4
7 1
8 2
9 8
10 9

Sample 3 Output

4
4
5
6
6
7
5
5
6
7

8
1 4
5 6
4 5
6 7
6 8
2 4
3 4

4
4
4
3
2
3
4
4

Source/Category