CF682C.Alyona and the Tree
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 1, 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 v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > a__u, where a__u is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u.
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?
阿廖娜决定节食,于是前往森林采摘苹果。在那里,她意外地发现了一棵神奇的有根树,其根节点为顶点 1,树的每个顶点和每条边上都写有一个数字。
女孩注意到树中有一些顶点是“悲伤的”,于是决定与它们玩个游戏。我们称顶点 v 是悲伤的,当且仅当在顶点 v 的子树中存在某个顶点 u,使得 dist(v,u)>au,其中 au 表示顶点 u 上所写的数字,dist(v,u) 表示从 v 到 u 的路径上所有边上的数字之和。
树的叶子节点是指仅通过一条边与唯一一个顶点相连的顶点;但树的根节点仅当整棵树仅含一个顶点(即根节点本身)时,才被视为叶子节点。
因此,阿廖娜决定不断删除树的一些叶子节点,直到树中不再存在任何悲伤的顶点为止。请问:阿廖娜最少需要删除多少片叶子?
输入格式
In the first line of the input integer n (1 ≤ n ≤ 105) is given — the number of vertices in the tree.
In the second line the sequence of n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109) is given, where a__i is the number written on vertex i.
The next n - 1 lines describe tree edges: i__th of them consists of two integers p__i and c__i (1 ≤ p__i ≤ n, - 109 ≤ c__i ≤ 109), meaning that there is an edge connecting vertices i + 1 and p__i with number c__i written on it.
输入的第一行给出一个整数 n(1≤n≤105)——树中顶点的数量。
第二行给出一个由 n 个整数 a1,a2,…,an(1≤ai≤109)组成的序列,其中 ai 表示写在第 i 个顶点上的数。
接下来的 n−1 行描述树的边:第 i 行包含两个整数 pi 和 ci(1≤pi≤n,−109≤ci≤109),表示存在一条连接顶点 i+1 与 pi 的边,且该边上写着数字 ci。
输出格式
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.
输出唯一的整数——Alyona 需要移除的最少叶子节点数量,使得树中不再存在任何“悲伤”顶点。
输入输出样例
输入#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:

以下图片表示从树中移除叶子节点的可能过程:

输入解题思路,AI测评打分。不知道怎么写?