Mr. Ham is one of the most famous architects in Hefei and has been invited to participate in the planning of the new campus of USTC.
Specifically, the campus of USTC can be considered as a tree $$$T=(V, E)$$$, with $$$n$$$ buildings and $$$n-1$$$ undirected edges, building $$$i$$$ having an importance value $$$w_i$$$. It is guaranteed that the USTC campus is connected.
The university hopes that Mr. Ham can divide the campus into several regions. We consider a partition plan is legal if and only if it satisfies the following conditions:
The university considers the weight of a region to be the second highest importance value among all buildings in that region, and if the region contains only one building, its weight is $$$0$$$. The university hopes that Mr. Ham can maximize the sum weights of all regions. Can you help Mr. Ham get the answer?
Induced subgraph: If a region is composed of buildings from the set $$$S\subseteq V$$$, then its induced subgraph contains all the buildings in the set $$$S$$$ and edges whose endpoints are both in the set $$$S$$$.
The first line contains a positive integer $$$n(1\le n\le 5\times 10^5)$$$ indicating the number of buildings.
The second line contains $$$n$$$ positive integers $$$w_i(1\le w_i\le 10^9)$$$ indicating the weight of each building.
The next $$$n-1$$$ lines contain the edges of the USTC campus, one edge per line. The $$$i$$$-th line contains two integers $$$u_i$$$, $$$v_i$$$$$$(1\le u_i,v_i\le n,u_i\ne v_i)$$$ indicating an edge $$$(u,v)$$$. It is guaranteed that it forms a tree.
Output a single line containing only one integer indicating the maximum sum weight of all regions.
82 5 4 5 3 1 1 31 21 31 42 52 63 74 8
8