Longest Path
题号:NC17140
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

In ICPCCamp, there are n cities numbered with 1, 2, ..., n and (n - 1) bidirectional roads. The i-th road has color ci and connects cities ai and bi. It is guaranteed that cities can reach each other.
Going from city u to city v via the unique shortest path, one may pass roads e1, e2, ..., ek in order. Bobo denotes as d(u, v).
For each city u, find out .

输入描述:

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The i-th of the following (n - 1) lines contains 3 integers ai, bi, ci.

输出描述:

For each test case, print n integers f1, f2, ..., fn.
示例1

输入

复制
2
1 2 1
4
1 2 1
2 3 2
3 4 1

输出

复制
0
0
2
1
1
2

备注:

* 1 ≤ n ≤ 105
* 1 ≤ ai, bi ≤ n
* 1 ≤ ci ≤ 105
* The sum of n does not exceed 106.