#abc222f. [abc222_f]Expensive Expense

[abc222_f]Expensive Expense

Problem Statement

The Kingdom of AtCoder is composed of NN towns and N1N-1 roads.
The towns are labeled as Town 11, Town 22, dots\\dots, Town NN. Similarly, the roads are labeled as Road 11, Road 22, dots\\dots, Road N1N-1. Road ii connects Towns AiA_i and BiB_i bidirectionally, and you have to pay the toll of CiC_i to go through it. For every pair of different towns (i,j)(i, j), it is possible to go from Town AiA_i to Town BjB_j via the roads.

You are given a sequence D=(D1,D2,dots,DN)D = (D_1, D_2, \\dots, D_N), where DiD_i is the cost to do sightseeing in Town ii. Let us define the travel cost Ei,jE_{i,j} from Town ii to Town jj as the total toll incurred when going from Town ii to Town jj, plus DjD_{j}.

  • More formally, Ei,jE_{i,j} is defined as Dj+displaystylesuml=0k1clD_j + \\displaystyle\\sum_{l=0}^{k-1} c_l, where the shortest path between ii and jj is i=p0,p1,dots,pk1,pk=ji = p_0, p_1, \\dots, p_{k-1}, p_k = j and the toll for the road connecting Towns plp_{l} and pl+1p_{l+1} is clc_l.

For every ii, find the maximum possible travel cost when traveling from Town ii to another town.

  • More formally, for every ii, find max1leqjleqN,jneqiEi,j\\max_{1 \\leq j \\leq N, j \\neq i} E_{i,j}.

Constraints

  • 2leqNleq2times1052 \\leq N \\leq 2 \\times 10^5
  • 1leqAileqN1 \\leq A_i \\leq N (1leqileqN1)(1 \\leq i \\leq N-1)
  • 1leqBileqN1 \\leq B_i \\leq N (1leqileqN1)(1 \\leq i \\leq N-1)
  • 1leqCileq1091 \\leq C_i \\leq 10^9 (1leqileqN1)(1 \\leq i \\leq N-1)
  • 1leqDileq1091 \\leq D_i \\leq 10^9 (1leqileqN)(1 \\leq i \\leq N)
  • It is possible to travel from Town ii to Town jj via some number of roads, for a pair of integers (i,j)(i,j) such that 1leqiltjleqN1 \\leq i \\lt j \\leq N.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN A1A_1 B1B_1 C1C_1 A2A_2 B2B_2 C2C_2 vdots\\vdots AN1A_{N-1} BN1B_{N-1} CN1C_{N-1} D1D_1 D2D_2 dots\\dots DND_N

Output

Print NN lines. The ii-th line should contain $\\displaystyle \\max_{1 \\leq j \\leq N, j \\neq i} E_{i,j}$.


Sample Input 1

3
1 2 2
2 3 3
1 2 3

Sample Output 1

8
6
6

The value of Ei,jE_{i,j} for every ordered pair of towns (i,j)(i,j) is as follows.

  • E1,2=2+2=4E_{1,2} = 2 + 2 = 4
  • E1,3=5+3=8E_{1,3} = 5 + 3 = 8
  • E2,1=2+1=3E_{2,1} = 2 + 1 = 3
  • E2,3=3+3=6E_{2,3} = 3 + 3 = 6
  • E3,1=5+1=6E_{3,1} = 5 + 1 = 6
  • E3,2=3+2=5E_{3,2} = 3 + 2 = 5

Sample Input 2

6
1 2 3
1 3 1
1 4 4
1 5 1
1 6 5
9 2 6 5 3 100

Sample Output 2

105
108
106
109
106
14

Sample Input 3

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

Sample Output 3

5000000006
4000000006
3000000006
3000000001
4000000001
5000000001