问题 L: Landmine

内存限制:512 MB 时间限制:16 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Given a tree where each edge has a length. Each node contains a landmine, and the i-th node's landmine has an explosion radius of ri.

We define dist(i,j) as the shortest distance between vertex i and vertex j in the tree. In other words, dist(i,j) is the sum of edge lengths along the unique simple path between vertex i and vertex j.

When the landmine at vertex i explodes, after one second, all landmines within distance ri from vertex i will explode together. In other words, for all landmines j satisfyingdist(i,j)ri, if they have not exploded yet, they will be detonated one second after the landmine at vertex i explodes.

For each i=2,3,,n, you want to calculate how long it will take for the first landmine at vertex 1 to be detonated after detonating the landmine at vertex i, or if it can never be detonated.

 

输入格式

The input consists of multiple test cases. The first line contains a single integer T (1T100) - the number of test cases. Description of the test cases follows.

The first line of each test case contains one integer n (1n105).

The second line contains n - 1 integers r2,r3,,rn (0ri1018).

Each of the following n - 1 lines contains three integers u, v, w (1u,vnu=v1wi1012) - an edge between u and v with a length of w.

It's guaranteed that n106.

 

输出格式

For each test case, print n - 1n1 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 -11.

输入样例 复制

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

输出样例 复制

2 1
1 1 2 -1

分类标签