CF739B.Alyona and a tree

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alyona has a tree with nn vertices. The root of the tree is the vertex 11 . In each vertex Alyona wrote an positive integer, in the vertex ii she wrote aia_{i} . Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges).

Let's define dist(v,u)dist(v,u) as the sum of the integers written on the edges of the simple path from vv to uu .

The vertex vv controls the vertex uu ( vuv≠u ) if and only if uu is in the subtree of vv and dist(v,u)<=audist(v,u)<=a_{u} .

Alyona wants to settle in some vertex. In order to do this, she wants to know for each vertex vv what is the number of vertices uu such that vv controls uu .

输入格式

The first line contains single integer nn ( 1<=n<=21051<=n<=2·10^{5} ).

The second line contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1091<=a_{i}<=10^{9} ) — the integers written in the vertices.

The next (n1)(n-1) lines contain two integers each. The ii -th of these lines contains integers pip_{i} and wiw_{i} ( 1<=pi<=n1<=p_{i}<=n , 1<=wi<=1091<=w_{i}<=10^{9} ) — the parent of the (i+1)(i+1) -th vertex in the tree and the number written on the edge between pip_{i} and (i+1)(i+1) .

It is guaranteed that the given graph is a tree.

输出格式

Print nn integers — the ii -th of these numbers should be equal to the number of vertices that the ii -th vertex controls.

输入输出样例

  • 输入#1

    5
    2 5 1 4 6
    1 7
    1 1
    3 5
    3 6
    

    输出#1

    1 0 1 0 0
    
  • 输入#2

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

    输出#2

    4 3 2 1 0
    

说明/提示

In the example test case the vertex 11 controls the vertex 33 , the vertex 33 controls the vertex 55 (note that is doesn't mean the vertex 11 controls the vertex 55 ).

首页