#P15751. [JAG 2024 Summer Camp #3] Fragile Tree

[JAG 2024 Summer Camp #3] Fragile Tree

题目描述

In the ICPC Park, there is a giant tree where a group of squirrels has made their nests.

The squirrels' nests consist of NN rooms numbered 1,2,,N1, 2, \ldots, N and N1N - 1 bidirectional roads numbered 1,2,,N11, 2, \ldots, N - 1 that connect the rooms. It is guaranteed that any two rooms can be reached from each other by following the roads.

Room 11 is the gathering place for the group, while the other rooms serve as sleeping quarters. Each room ii has aia_i squirrels living in it, where a1=0a_1 = 0.

Now, the squirrels are trying to gather in Room 11 for a morning assembly by following the roads from their sleeping quarters. However, due to a severe storm last night, each road has become fragile, and the ii-th road can only allow up to cic_i squirrels to pass through before it collapses.

As an animal lover, your task is to choose one road to reinforce in order to maximize the number of squirrels that can reach Room 11. The reinforced road will not collapse, no matter how many squirrels pass through it.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &N \\ &a_1 \ a_2 \ \ldots \ a_N \\ &u_1 \ v_1 \ c_1 \\ &u_2 \ v_2 \ c_2 \\ &\vdots \\ &u_{N-1} \ v_{N-1} \ c_{N-1} \end{aligned} $$

The first line consists of an integer NN between 22 and 200,000200,000, inclusive.

The second line contains NN non-negative integers a1,a2,,aNa_1, a_2, \ldots, a_N. The integer aia_i denotes the number of squirrels living in Room ii, with a1=0a_1 = 0 and 0ai1090 \leq a_i \leq 10^9 (i=2,3,,Ni = 2, 3, \ldots, N).

Each of the following N1N - 1 lines contains three integers uiu_i, viv_i and cic_i (1ui,viN1 \leq u_i, v_i \leq N, 0ci1090 \leq c_i \leq 10^9). uiu_i and viv_i denote the endpoints of the ii-th road, and cic_i denotes its durability.

It is guaranteed that the given graph is a tree.

输出格式

Print the maximum number of squirrels that can reach Room 11.

8
0 11 13 14 17 19 15 12
1 2 5
2 3 2
3 4 3
1 5 2
5 6 5
1 7 4
7 8 3
31