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

Magic boy Bi Luo with his excited tree

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2880    Accepted Submission(s): 860


Problem Description
Bi Luo is a magic boy, he also has a migic tree, the tree has $N$ nodes , in each node , there is a treasure, it's value is $V[i]$, and for each edge, there is a cost $C[i]$, which means every time you pass the edge $i$ , you need to pay $C[i]$.

You may attention that every $V[i]$ can be taken only once, but for some $C[i]$ , you may cost severial times.

Now, Bi Luo define $ans[i]$ as the most value can Bi Luo gets if Bi Luo starts at node $i$.

Bi Luo is also an excited boy, now he wants to know every $ans[i]$, can you help him?
 

Input
First line is a positive integer $T( T \leq 10^4)$ , represents there are $T$ test cases.

Four each test:

The first line contain an integer $N$$( N \leq 10^5 )$.

The next line contains $N$ integers $V[i]$, which means the treasure’s value of node $i ( 1 \leq V[i] \leq 10^4 )$.

For the next $N - 1$ lines, each contains three integers $u , v , c$ , which means node $u$ and node $v$ are connected by an edge, it's cost is $c (1 \leq c \leq 10^4 )$.

You can assume that the sum of $N$ will not exceed $10^6$.
 

Output
For the i-th test case , first output Case #i: in a single line , then output $N$ lines , for the i-th line , output $ans[i]$ in a single line.
 

Sample Input
1 5 4 1 7 7 7 1 2 6 1 3 1 2 4 8 3 5 2
 

Sample Output
Case #1: 15 10 14 9 15
 

Author
UESTC
 

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-05 00:05:40, Gzip enabled