This page is still under construction.

Parts of this page are still being built. What you see may change.

Balanced Development

Time limit5sMemory limit512 MB

Summary
Given a weighted tree and an activation permutation, find when each region activates as ancestor population inflows trigger chain activations.
Level

Hard8 of 10

Topics
Tree, Simulation, DFS, Segment tree
Solved
No attempts yet

Problem

In the 2062 presidential election, Kyeonggwak-dang Jeong-hu won the presidency by defeating Dong-hyeon, an independent candidate.

For his balanced regional development pledge, Jeong-hu first built a tree of target regions. The tree has NN carefully chosen target regions as vertices and N−1N-1 edges, each connecting two regions. Region 1, where Gyeonggi Science High School is located, is the root.

Next, Jeong-hu drew up a development plan, which is a permutation TT of length NN that gives the activation order of the NN target regions. The current time is 0, and at time ii, region TiT_i is activated. During this process, an activation not in the plan can occur when a region's cumulative inflow population reaches CiC_i or more. The cumulative inflow population of every region starts at 0.

Whether or not it is in the plan, when region ii is activated, a population movement of XiX_i immediately occurs in every descendant region within distance RiR_i, that is, every region that has ii as an ancestor and lies at distance RiR_i or less from ii. In other words, the cumulative inflow population of every child region within distance RiR_i increases by XiX_i. Activations can chain. When several chain activation orders are possible, activations happen in any one of those orders.

Find the activation time of each region to help Jeong-hu review the development plan.

Input

The first line contains an integer NN. Each of the next N−1N-1 lines contains three integers uiu_i, viv_i, wiw_i, meaning regions uiu_i and viv_i are connected by a road of length wiw_i. The next line contains NN integers TiT_i, separated by spaces. Each of the next NN lines contains three integers CiC_i, RiR_i, XiX_i, separated by spaces, with the ii-th of these lines describing region ii.

Output

Print NN integers on a single line, separated by spaces, giving the activation time of each region in order.

Constraints

  • 1≤N≤2000001 \le N \le 200000
  • 1≤Ti≤N1 \le T_i \le N
  • If i≠ji \ne j, then Ti≠TjT_i \ne T_j.
  • 0≤Ri≤10150 \le R_i \le 10^{15}
  • 1≤Ci≤10151 \le C_i \le 10^{15}
  • 1≤Xi,wi≤1091 \le X_i, w_i \le 10^{9}
  • 1≤ui,vi≤N1 \le u_i, v_i \le N, ui≠viu_i \ne v_i
  • There are no duplicate edges.
  • All given numbers are integers.
  • The target regions form a tree.

Examples1

  1. Example 1

    Input
    5
    1 2 1
    2 3 1
    3 4 1
    2 5 1
    1 2 3 4 5
    5 2 1
    6 1 2
    3 1 2
    2 1 1
    4 1 1
    
    Expected output
    1 2 2 2 5