Happy Tree

Find the minimum number of leaves to remove so that no remaining vertex has a descendant whose path distance exceeds that descendant's value.

Medium6TreeDFSGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

There is a tree with NN vertices numbered 1 to NN, rooted at vertex 1. Every vertex and every edge carries one number. Write aua_u for the number on vertex uu, and dist(v,u)\mathrm{dist}(v, u) for the sum of the numbers on the edges along the path from vv to uu.

A vertex vv is sad if the subtree rooted at vv contains at least one vertex uu with dist(v,u)>au\mathrm{dist}(v, u) > a_u. A tree with no sad vertex is a happy tree.

Minju cannot lift anything heavier than a keyboard, so she can cut leaves only. A leaf is a vertex with no child, that is, a vertex whose only neighbour is its parent. The root is a leaf only when it is the last vertex left in the tree. Cutting a vertex removes it from the tree, and a vertex that becomes a leaf as a result can be cut next.

Find the minimum number of vertices Minju has to cut to make the tree happy.

In the tree drawn as 1) below, the 5 vertices marked 2) to 6) have to be cut.

Input

The first line contains the number of vertices NN (1N1000001 \le N \le 100\,000).

The second line contains a1,a2,,aNa_1, a_2, \ldots, a_N (1ai10000000001 \le a_i \le 1\,000\,000\,000), the numbers written on vertices 1 to NN, separated by spaces.

Each of the next N1N - 1 lines contains two integers. Line ii contains pip_i (1piN1 \le p_i \le N) and cic_i (1000000000ci1000000000-1\,000\,000\,000 \le c_i \le 1\,000\,000\,000), meaning that vertex i+1i + 1 and vertex pip_i are joined by an edge whose number is cic_i. The given edges always form a tree.

pip_i can be larger than i+1i + 1, so you have to work out the parent and child relations yourself by rooting the tree at vertex 1.

Output

Print the minimum number of leaves that have to be cut to make the tree happy, on one line.