The Fair Nut and the Best Path

题意翻译

给定一棵包含 $n$ 个结点的树,树上的每个结点拥有点权 $w_i$,每一条边拥有边权 $c_i$。你可以从树的某个结点出发,沿着树边通往一个未曾经过的结点。每当你到达一个新的结点(包括起点)时,你能获得该结点点权的收益,同时,每经过一条树边,你都会损失该条边边权的收益。你需要规划出一条路径,使得你在沿着该路径行进的任意时刻收益值均非负,且行进结束时的收益值应尽可能大。输出结束时的最大收益值。 $1 \leq n \leq 3 \times 10^5, 0 \leq w_i \leq 10^9, 1 \leq c_i \leq 10^9$,输入保证给出的图是一棵树。

题目描述

The Fair Nut is going to travel to the Tree Country, in which there are $ n $ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car in the city $ u $ and go by a simple path to city $ v $ . He hasn't determined the path, so it's time to do it. Note that chosen path can consist of only one vertex. A filling station is located in every city. Because of strange law, Nut can buy only $ w_i $ liters of gasoline in the $ i $ -th city. We can assume, that he has infinite money. Each road has a length, and as soon as Nut drives through this road, the amount of gasoline decreases by length. Of course, Nut can't choose a path, which consists of roads, where he runs out of gasoline. He can buy gasoline in every visited city, even in the first and the last. He also wants to find the maximum amount of gasoline that he can have at the end of the path. Help him: count it.

输入输出格式

输入格式


The first line contains a single integer $ n $ ( $ 1 \leq n \leq 3 \cdot 10^5 $ ) — the number of cities. The second line contains $ n $ integers $ w_1, w_2, \ldots, w_n $ ( $ 0 \leq w_{i} \leq 10^9 $ ) — the maximum amounts of liters of gasoline that Nut can buy in cities. Each of the next $ n - 1 $ lines describes road and contains three integers $ u $ , $ v $ , $ c $ ( $ 1 \leq u, v \leq n $ , $ 1 \leq c \leq 10^9 $ , $ u \ne v $ ), where $ u $ and $ v $ — cities that are connected by this road and $ c $ — its length. It is guaranteed that graph of road connectivity is a tree.

输出格式


Print one number — the maximum amount of gasoline that he can have at the end of the path.

输入输出样例

输入样例 #1

3
1 3 3
1 2 2
1 3 2

输出样例 #1

3

输入样例 #2

5
6 3 2 5 0
1 2 10
2 3 3
2 4 1
1 5 1

输出样例 #2

7

说明

The optimal way in the first example is $ 2 \to 1 \to 3 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1083A/9cde903713bc2c3037de1f95f6d689e21702b992.png)The optimal way in the second example is $ 2 \to 4 $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1083A/ba9b6431b860ed0c426ce30e31a270fdf4bfbaf1.png)