#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 rooms numbered and bidirectional roads numbered that connect the rooms. It is guaranteed that any two rooms can be reached from each other by following the roads.
Room is the gathering place for the group, while the other rooms serve as sleeping quarters. Each room has squirrels living in it, where .
Now, the squirrels are trying to gather in Room 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 -th road can only allow up to 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 . 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 between and , inclusive.
The second line contains non-negative integers . The integer denotes the number of squirrels living in Room , with and ().
Each of the following lines contains three integers , and (, ). and denote the endpoints of the -th road, and denotes its durability.
It is guaranteed that the given graph is a tree.
输出格式
Print the maximum number of squirrels that can reach Room .
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