Under construction

Still being built. Things may change

Mines

Time limit9sMemory limit1024 MB

Summary
For each vertex of a weighted tree, count how many mines explode when that mine is detonated, given that each blast reaches all mines within its radius along tree distance.
Level

Hard9 of 10

Topics
Tree, Divide and conquer, Graph, Sorting
Solved
No attempts yet

Problem

"Maybe we could dig up some old problem with a sequence and have them solve it on a tree?"


Problem author

You are given a tree (an undirected acyclic graph) where every edge has a length. Each vertex of the tree holds a mine with a blast radius. When a mine explodes, every mine at a vertex within distance at most its blast radius also explodes, and the chain continues. The distance between two vertices is the sum of the edge lengths on the simple path between them. For each mine, determine how many mines explode when you detonate that one mine by hand. Each manual detonation is considered independently of the manual detonations of the other mines.

Input

The first line contains an integer nn (1≤n≤1000001 \le n \le 100000), the number of vertices in the tree, which is also the number of mines. The vertices are numbered from 1 to nn.

The second line contains nn integers r1,r2,…,rnr_1, r_2, \ldots, r_n (0≤ri≤10180 \le r_i \le 10^{18}), where rir_i is the blast radius of the mine at vertex ii.

The next n−1n-1 lines each contain three integers aia_i, bib_i, cic_i (1≤ai,bi≤n1 \le a_i, b_i \le n; 1≤ci≤10121 \le c_i \le 10^{12}), meaning there is an edge of length cic_i connecting vertices aia_i and bib_i. The input is guaranteed to describe a valid tree.

Output

Print one line with nn integers. The ii-th integer is the number of mines that explode when you detonate the mine at vertex ii by hand.

Hint

Explanation of the example: the example tree is shown below.

When the mine at the fourth vertex is detonated by hand, its blast sets off the mines at the first and second vertices. The mine at the first vertex then sets off the mine at the fifth vertex. In total, four mines explode.

Examples1

  1. Example 1

    Input
    5
    8 1 0 4 6
    2 4 2
    3 1 9
    2 5 5
    2 1 2
    
    Expected output
    4 1 1 4 2