In ICPCCamp, there are n cities numbered with 1, 2, ..., n and (n - 1) bidirectional roads. The i-th road has color c
i and connects cities a
i and b
i. 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 e
1, e
2, ..., e
k in order. Bobo denotes
%5E2%20%2B%20%5Cdots%20%2B%20(c_%7Be_k%7D%20-%20c_%7Be_%7Bk%20-%201%7D%7D)%5E2)
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
备注:
* 1 ≤ n ≤ 105
* 1 ≤ ai, bi ≤ n
* 1 ≤ ci ≤ 105
* The sum of n does not exceed 106.