Score : $500$ points
The Kingdom of AtCoder is composed of $N$ towns and $N-1$ roads.
The towns are labeled as Town $1$, Town $2$, $\dots$, Town $N$.
Similarly, the roads are labeled as Road $1$, Road $2$, $\dots$, Road $N-1$.
Road $i$ connects Towns $A_i$ and $B_i$ bidirectionally, and you have to pay the toll of $C_i$ to go through it. For every pair of different towns $(i, j)$, it is possible to go from Town $A_i$ to Town $B_j$ via the roads.
You are given a sequence $D = (D_1, D_2, \dots, D_N)$, where $D_i$ is the cost to do sightseeing in Town $i$. Let us define the travel cost $E_{i,j}$ from Town $i$ to Town $j$ as the total toll incurred when going from Town $i$ to Town $j$, plus $D_{j}$.
For every $i$, find the maximum possible travel cost when traveling from Town $i$ to another town.
Input is given from Standard Input in the following format:
$N$ $A_1$ $B_1$ $C_1$ $A_2$ $B_2$ $C_2$ $\vdots$ $A_{N-1}$ $B_{N-1}$ $C_{N-1}$ $D_1$ $D_2$ $\dots$ $D_N$
Print $N$ lines. The $i$-th line should contain $\displaystyle \max_{1 \leq j \leq N, j \neq i} E_{i,j}$.
3 1 2 2 2 3 3 1 2 3
8 6 6
The value of $E_{i,j}$ for every ordered pair of towns $(i,j)$ is as follows.
6 1 2 3 1 3 1 1 4 4 1 5 1 1 6 5 9 2 6 5 3 100
105 108 106 109 106 14
6 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 5 6 1000000000 1 2 3 4 5 6
5000000006 4000000006 3000000006 3000000001 4000000001 5000000001