Easily Happy Tree

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 MB

Problem

A tree has NN vertices numbered 1 through NN, 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 vv is sad when the subtree rooted at vv holds at least one vertex uu with dist(v,u)>au\mathrm{dist}(v, u) > a_u. Here aua_u is the number written on vertex uu, and dist(v,u)\mathrm{dist}(v, u) is the sum of the numbers written on the edges along the path from vv to uu.

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.

Input

The first line contains the number of vertices NN (1N100,0001 \le N \le 100{,}000).

The second line contains the numbers aia_i written on vertices 1 through NN, in that order (1ai1,000,000,0001 \le a_i \le 1{,}000{,}000{,}000).

Each of the next N1N - 1 lines describes one edge. The two integers pip_i and cic_i on the ii-th of those lines (1piN1 \le p_i \le N, 0ci1,000,000,0000 \le c_i \le 1{,}000{,}000{,}000) mean that vertex (i+1)(i + 1) is joined to vertex pip_i by an edge whose number is cic_i. When the tree is rooted at vertex 1, vertex pip_i is not guaranteed to be the parent of vertex (i+1)(i + 1). The N1N - 1 edges always form a tree.

Output

Print the smallest number of leaves that have to be cut to make the tree happy.