标签:san ted btn sip connect elements number eterm nec
A. Radio Prize
All boring tree-shaped lands are alike, while all exciting tree-shaped lands are exciting in their own special ways.What makes Treeland more exciting than the other tree-shaped lands are the raddest radio hosts in the local area: Rootand Leaf. Every morning on FM 32:33 (repeating of course), Root and Leaf of The Full Depth Morning Show serveup the hottest celebrity gossip and traffic updates.
The region of Treeland is made of nn cities, connected by n - 1n−1 roads such that between every pair of cities there isexactly one simple path. The iith road connects cities u_iui? and v_ivi?, and has a toll of w_iwi?.
To reward their loyal listeners, The Full Depth Morning Show is giving away a number of travel packages! Root andLeaf will choose n - 1n−1 lucky residents from the city that sends them the most fan mail. Each of those residents thengets a distinct ticket to a different city in Treeland.
Each city in Treeland has its own tax on prizes: t_iti?. Let d_{u,v}du,v?be the sum of the tolls on each road on the only simplepath from city uu to vv. For a trip from city uu to city vv, the cost of that trip is then (t_u + t_v)d_{u,v}(tu?+tv?)du,v?.
The shock jocks haven’t quite thought through how much their prize is worth. They need to prepare a report to theradio executives, to summarize the expected costs. For each city that could win the prize, what is the total cost ofpurchasing all the tickets?
The first line of input is a single integer n (1 \leq≤ n \leq≤ 100 000). The next line has nnspace-separated integers t_iti?(1 \leq t_i \leq 1 0001≤ti?≤1000), the tax in each city. The following n - 1n−1 lines each have 3 integers, u_i,v_i,w_iui?,vi?,wi?, meaning the iith roadconnects cities u_iui? and v_ivi?(1 \leq u_i,v_i \leq n1≤ui?,vi?≤n), with a toll of w_iwi? (1 \leq w_i \leq 1 0001≤w