Codeforces Round 381 (Div. 1)
B
Alyona and a tree
Codeforces
1900
原题
← AC →
翻译中…

Alyona has a tree with $*n*$ vertices. The root of the tree is the vertex $1$. In each vertex Alyona wrote an positive integer, in the vertex $*i*$ she wrote $*a*_{*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*)$ as the sum of the integers written on the edges of the simple path from $*v*$ to $*u*$.

翻译中…

The vertex $*v*$ controls the vertex $*u*$ ($*v* ≠ *u*$) if and only if $*u*$ is in the subtree of $*v*$ and $*dist*(*v*, *u*) ≤ *a*_{*u*}$.

翻译中…

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

翻译中…

Input

翻译中…

The first line contains single integer $*n*$ ($1 ≤ *n* ≤ 2·10^{5}$).

翻译中…

The second line contains $*n*$ integers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ ($1 ≤ *a*_{*i*} ≤ 10^{9}$) — the integers written in the vertices.

翻译中…

The next $(*n* - 1)$ lines contain two integers each. The $*i*$-th of these lines contains integers $*p*_{*i*}$ and $*w*_{*i*}$ ($1 ≤ *p*_{*i*} ≤ *n*$, $1 ≤ *w*_{*i*} ≤ 10^{9}$) — the parent of the $(*i* + 1)$-th vertex in the tree and the number written on the edge between $*p*_{*i*}$ and $(*i* + 1)$.

翻译中…

It is guaranteed that the given graph is a tree.

翻译中…

Output

翻译中…

Print $*n*$ integers — the $*i*$-th of these numbers should be equal to the number of vertices that the $*i*$-th vertex controls.

翻译中…

Note

翻译中…

In the example test case the vertex $1$ controls the vertex $3$, the vertex $3$ controls the vertex $5$ (note that is doesn't mean the vertex $1$ controls the vertex $5$).

翻译中…

样例

Input #1
5
2 5 1 4 6
1 7
1 1
3 5
3 6
Output #1
1 0 1 0 0
InputCopy OutputCopy
Input #2
5
9 7 8 6 5
1 1
2 1
3 1
4 1
Output #2
4 3 2 1 0
InputCopy OutputCopy
题目信息
题号
739B
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。