#P9875. L. Landmine

L. Landmine

L. Landmine

Problem Description

Given a tree where each edge has a length. Each node contains a landmine, and the ii-th node's landmine has an explosion radius of rir_i. We define dist(i,j)dist(i,j) as the shortest distance between vertex ii and vertex jj in the tree. In other words, dist(i,j)dist(i,j) is the sum of edge lengths along the unique simple path between vertex ii and vertex jj. When the landmine at vertex ii explodes, after one second, all landmines within distance rir_i from vertex ii will explode together. In other words, for all landmines jj satisfying dist(i,j)ridist(i,j) \leq r_i, if they have not exploded yet, they will be detonated one second after the landmine at vertex ii explodes. For each i=2,3,,ni = 2, 3, \dots, n, you want to calculate how long it will take for the first landmine at vertex 11 to be detonated after detonating the landmine at vertex ii, or if it can never be detonated.

Input

The input consists of multiple test cases. The first line contains a single integer TT (1T1001 \le T \le 100) - the number of test cases. Description of the test cases follows. The first line of each test case contains one integer nn (1n1051 \le n \le 10 ^ 5). The second line contains n1n - 1 integers r2,r3,,rnr_2, r_3, \dots, r_n (0ri10180 \le r_i \le 10 ^ {18}). Each of the following n1n - 1 lines contains three integers u,v,wu, v, w (1u,vn1\leq u,v\leq n, uvu\neq v, 1wi10121 \le w_i \le 10 ^ {12}) - an edge between uu and vv with a length of ww. It's guaranteed that n106\sum n \leq 10^6.

Output

For each test case, print n1n - 1 integers - the time in seconds after detonating the landmine at vertex ii, at which the first landmine at vertex 11 will be detonated. If it can never be detonated, output 1-1.

Sample Input

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

Sample Output

2 1
1 1 2 -1

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)