F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

L. Landmine

Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 375    Accepted Submission(s): 127


Problem Description
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 $r_i$.

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 $r_i$ from vertex $i$ will explode together. In other words, for all landmines $j$ satisfying $dist(i,j) \leq r_i$, if they have not exploded yet, they will be detonated one second after the landmine at vertex $i$ explodes.

For each $i = 2, 3, \dots, 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.
 

Input
The input consists of multiple test cases. The first line contains a single integer $T$ ($1 \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 $n$ ($1 \le n \le 10 ^ 5$).

The second line contains $n - 1$ integers $r_2, r_3, \dots, r_n$ ($0 \le r_i \le 10 ^ {18}$).

Each of the following $n - 1$ lines contains three integers $u, v, w$ ($1\leq u,v\leq n$, $u\neq v$, $1 \le w_i \le 10 ^ {12}$) - an edge between $u$ and $v$ with a length of $w$.

It's guaranteed that $\sum n \leq 10^6$.
 

Output
For each test case, print $n - 1$ integers - the time in seconds after detonating the landmine at vertex $i$, at which the first landmine at vertex $1$ will be detonated. If it can never be detonated, output $-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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-19 10:01:51, Gzip enabled