Full Depth Morning Show

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

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: Root and Leaf. Every morning on FM 32.3332.33 (repeating of course), Root and Leaf of The Full Depth Morning Show serve up the hottest celebrity gossip and traffic updates.

The region of Treeland is made of nn cities, connected by n1n - 1 roads such that between every pair of cities there is exactly one simple path. The iith road connects cities u_iu\_i and v_iv\_i, and has a toll of w_iw\_i.

To reward their loyal listeners, The Full Depth Morning Show is giving away a number of travel packages! Root and Leaf will choose n1n - 1 lucky residents from the city that sends them the most fan mail. Each of those residents then gets a distinct ticket to a different city in Treeland.

Each city in Treeland has its own tax on prizes: t_it\_i. Let d_u,vd\_{u, v} be the sum of the tolls on each road on the only simple path 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(t\_u + t\_v) d\_{u, v}.

Figure 1: The map of Treeland corresponding to the first sample input.

The shock jocks haven't quite thought through how much their prize is worth. They need to prepare a report to the radio executives, to summarize the expected costs. For each city that could win the prize, what is the total cost of purchasing all the tickets?

입력

The first line of input is a single integer nn (1n100,0001 \leq n \leq 100\\,000). The next line has nn space-separated integers t_it\_i (1t_i1,0001\leq t\_i \leq 1\\,000), the tax in each city. The following n1n - 1 lines each have 33 integers, u_i,v_i,w_iu\_i, v\_i, w\_i, meaning the iith road connects cities u_iu\_i and v_iv\_i (1u_i,v_in1 \le u\_i, v\_i \le n), with a toll of w_iw\_i (1w_i1,0001 \leq w\_i \leq 1\\,000).

출력

Output nn lines. On the iith line, output a single integer: the cost of purchasing tickets if city ii wins the contest.