#P9260. [PA 2022] Miny

[PA 2022] Miny

Problem Description

This problem is translated from PA 2022 Round 4 Miny.

You are given a tree (an undirected acyclic graph). Each edge of the tree has a fixed length. There is a mine at each node, and each mine has a fixed blast radius. If a mine explodes, then all mines whose distance to this mine is at most its blast radius will also explode.

The distance between two nodes is defined as the sum of edge lengths on the simple path between them. For each mine, if we manually detonate it, determine how many mines will explode. Note that for each mine, we consider manually detonating it to be independent of manually detonating any other mine.

Input Format

The first line contains an integer nn, the number of nodes in the tree (also the number of mines). The nodes are numbered from 11 to nn.

The second line contains nn integers r1,r2,,rnr_1, r_2, \ldots, r_n, where the ii-th integer is the blast radius of the mine at node ii.

The next n1n - 1 lines each contain three integers ai,bi,cia_i, b_i, c_i, meaning there is an edge of length cic_i connecting nodes aia_i and bib_i.

It is guaranteed that the input describes a tree.

Output Format

For 100%100\% of the testdata, the following is required:

Output one line with nn integers. The ii-th integer should be the number of mines that will explode if we manually detonate the mine at node ii.

5
8 1 0 4 6
2 4 2
3 1 9
2 5 5
2 1 2

4 1 1 4 2

Hint

1n1051 \le n \le 10^5, 0ri10180 \le r_i \le 10^{18}, 1ai,bin1 \le a_i, b_i \le n, 1ci10121 \le c_i \le 10^{12}.

Translated by ChatGPT 5