CF682C.Alyona and the Tree

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 11 , every vertex and every edge of which has a number written on.

The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex vv sad if there is a vertex uu in subtree of vertex vv such that dist(v,u)>a_{u} , where aua_{u} is the number written on vertex uu , dist(v,u)dist(v,u) is the sum of the numbers written on the edges on the path from vv to uu .

Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root.

Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove?

输入格式

In the first line of the input integer nn ( 1<=n<=1051<=n<=10^{5} ) is given — the number of vertices in the tree.

In the second line the sequence of nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1091<=a_{i}<=10^{9} ) is given, where aia_{i} is the number written on vertex ii .

The next n1n-1 lines describe tree edges: ithi^{th} of them consists of two integers pip_{i} and cic_{i} (1<=pi<=n(1<=p_{i}<=n , 109<=ci<=109)-10^{9}<=c_{i}<=10^{9}) , meaning that there is an edge connecting vertices i+1i+1 and pip_{i} with number cic_{i} written on it.

输出格式

Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree.

输入输出样例

  • 输入#1

    9
    88 22 83 14 95 91 98 53 11
    3 24
    7 -8
    1 67
    1 64
    9 65
    5 12
    6 -80
    3 8
    

    输出#1

    5
    

说明/提示

The following image represents possible process of removing leaves from the tree:

首页