#abc222f. F - Expensive Expense

F - Expensive Expense

Score : 500500 points

问题描述

AtCoder王国由NN个城镇和N1N-1条道路组成。
这些城镇分别标记为城镇1、城镇2、…、城镇NN。类似地,道路被标记为道路1、道路2、…、道路N1N-1。道路ii在城镇AiA_iBiB_i之间双向连接,通过它需要支付CiC_i的通行费。对于每一对不同的城镇(i,j)(i, j),都可以通过道路从城镇AiA_i到达城镇BjB_j

你得到了一个序列D=(D1,D2,,DN)D = (D_1, D_2, \dots, D_N),其中DiD_i是在城镇ii观光的成本。让我们定义从城镇ii到城镇jj的旅行成本Ei,jE_{i,j}为从城镇ii到城镇jj过程中所发生的全部通行费加上DjD_{j}

  • 更正式地说,Ei,jE_{i,j}被定义为Dj+l=0k1clD_j + \displaystyle\sum_{l=0}^{k-1} c_l,其中从iijj的最短路径为i=p0,p1,,pk1,pk=ji = p_0, p_1, \dots, p_{k-1}, p_k = j,连接城镇plp_{l}pl+1p_{l+1}的道路的通行费为clc_l

对于每个ii,求出从城镇ii出发前往另一个城镇的最大可能旅行成本。

  • 更正式地讲,对于每一个ii,求出max1jN,jiEi,j \max_{1 \leq j \leq N, j \neq i} E_{i,j}

以上为通义千问 qwen-max 翻译,仅供参考。

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, Town NN. Similarly, the roads are labeled as Road 11, Road 22, \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,,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+l=0k1clD_j + \displaystyle\sum_{l=0}^{k-1} c_l, where the shortest path between ii and jj is i=p0,p1,,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 max1jN,jiEi,j \max_{1 \leq j \leq N, j \neq i} E_{i,j}.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1AiN1 \leq A_i \leq N (1iN1)(1 \leq i \leq N-1)
  • 1BiN1 \leq B_i \leq N (1iN1)(1 \leq i \leq N-1)
  • 1Ci1091 \leq C_i \leq 10^9 (1iN1)(1 \leq i \leq N-1)
  • 1Di1091 \leq D_i \leq 10^9 (1iN)(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 1i<jN1 \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

AN1A_{N-1} BN1B_{N-1} CN1C_{N-1}

D1D_1 D2D_2 \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

update @ 2024/3/10 09:48:01