Delete the fewest leaves from a rooted tree so that no remaining vertex has a descendant farther away than that descendant's own limit a_u.
Hard8TreeDFSGreedyDynamic programmingNo attempts yetTime limit2sMemory limit512 MBA tree has N vertices numbered 1 through N, and vertex 1 is the root. Every vertex and every edge carries one number. Minju came back from an algorithm camp, visited a forest, and looked at this tree. Some of its vertices looked sad to her. The camp is over and she is in a good mood, so she wants to cut a few vertices and make the tree happy.
Vertex v is sad when the subtree rooted at v holds at least one vertex u with dist(v,u)>au. Here au is the number written on vertex u, and dist(v,u) is the sum of the numbers written on the edges along the path from v to u.
Minju cannot lift anything heavier than a keyboard, so she can cut only a leaf. A leaf is a vertex with no child, that is, a vertex whose only neighbor is its parent. Vertex 1 counts as a leaf only when a single vertex is left in the tree. Cutting a leaf can turn its parent into a new leaf, and that vertex can then be cut too.
Find the smallest number of vertices Minju has to cut so that no sad vertex is left.
In the picture below, 1) is the starting tree, and 2) through 6) are the five vertices that get cut, in order.

The first line contains the number of vertices N (1≤N≤100,000).
The second line contains the numbers ai written on vertices 1 through N, in that order (1≤ai≤1,000,000,000).
Each of the next N−1 lines describes one edge. The two integers pi and ci on the i-th of those lines (1≤pi≤N, 0≤ci≤1,000,000,000) mean that vertex (i+1) is joined to vertex pi by an edge whose number is ci. When the tree is rooted at vertex 1, vertex pi is not guaranteed to be the parent of vertex (i+1). The N−1 edges always form a tree.
Print the smallest number of leaves that have to be cut to make the tree happy.