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 MBThere is a tree with N vertices numbered 1 to N, rooted at vertex 1. Every vertex and every edge carries one number. Write au for the number on vertex u, and dist(v,u) for the sum of the numbers on the edges along the path from v to u.
A vertex v is sad if the subtree rooted at v contains at least one vertex u with dist(v,u)>au. 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.

The first line contains the number of vertices N (1≤N≤100000).
The second line contains a1,a2,…,aN (1≤ai≤1000000000), the numbers written on vertices 1 to N, separated by spaces.
Each of the next N−1 lines contains two integers. Line i contains pi (1≤pi≤N) and ci (−1000000000≤ci≤1000000000), meaning that vertex i+1 and vertex pi are joined by an edge whose number is ci. The given edges always form a tree.
pi can be larger than i+1, so you have to work out the parent and child relations yourself by rooting the tree at vertex 1.
Print the minimum number of leaves that have to be cut to make the tree happy, on one line.