/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int negs = 0;
        int pos = 0;
        int containsZero = false;
        int maxNegIdx = -1;
        int maxNeg = INT_MAX;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] < 0) {
                negs++;
            }
            else if (a[i] > 0) pos++;
            else containsZero = true;
        }
        sort(a.begin(), a.end());

        ll res = 1;
        // If All Negatives or zero
        if (pos == 0) {
            if (containsZero) res = 0;
            else {
                int r = n-1;
                int c = 0;
                ll prod = 1;
                while (c < 5) {
                    c++;
                    prod = prod * a[r];
                    r--;
                }
                res = prod;
            }
        } else {
            if (negs == 0) {
                int i = n-1;
                int c = 0;
                ll prod = 1;
                while (c < 5) {
                    prod = prod * a[i];
                    i--;
                    c++;
                }
                res = prod;
            } else {
                int c = 0;
                int l = 0;
                int r = n - 1;
                ll prod = 1;
                while (c < 4) {
                    ll lProd = (ll) a[l]*a[l+1];
                    ll rProd = (ll) a[r]*a[r-1];
                    if (lProd > rProd) {
                        prod = prod*lProd;
                        l += 2;
                        c+=2;
                    } else {
                        prod = prod*rProd;
                        r -= 2;
                        c += 2;
                    }
                }
                prod = prod * max(a[l] , a[r]);
                res = prod;
            }
        }

        cout<<res<<"\n";

    }
    return 0;
}


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

bool cmp(int a, int b) {
    return abs(a) < abs(b);
}
int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        int pos = 0;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
            if (a[i] > 0) pos++;
        }
        sort(a.begin(), a.end(), cmp);

        int r = n-1;
        ll prod = 1;

        if (pos == 0) {
            if (containsZero) {
                prod = 0;
            } else {
                for (int i=0; i < 5; i++) {
                    prod = prod*a[i];
                }
            }
        } else {
            for (int c=0; c < 5; c++) {
               prod = prod*a[r--];
            }
            int l = r;
            while (l >= 0) {
                ll p = prod;
                int c = a[l];
                for (int i = r+1; i < n; i++) {
                    if (a[i] != 0) {
                        ll x = (prod * c ) / a[i];
                        p = max(p, x);
                    }
                }
                prod = max(p, prod);
                l--;
            }
        }
        cout<<prod<<"\n";
    }
    return 0;
}


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

bool cmp(int a, int b) {
    return abs(a) < abs(b);
}
int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        int pos = 0;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
            if (a[i] > 0) pos++;
        }
        sort(a.begin(), a.end(), cmp);

        int r = n-1;
        ll prod = 1;

        if (pos == 0) {
            if (containsZero) {
                prod = 0;
            } else {
                for (int i=0; i < 5; i++) {
                    prod = prod*a[i];
                }
            }
        } else {
            for (int c=0; c < 4; c++) {
               prod = prod*a[r--];
            }
            int l = r;
            while (l >= 0) {
                ll p = prod;
                int c = a[l];
                for (int i = r+1; i < n; i++) {
                    if (a[i] != 0) {
                        ll x = (prod * c ) / a[i];
                        p = max(p, x);
                    }
                }
                prod = max(p, prod);
                l--;
            }
        }
        cout<<prod<<"\n";
    }
    return 0;
}


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

bool cmp(int a, int b) {
    return abs(a) < abs(b);
}
int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        int pos = 0;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
            if (a[i] > 0) pos++;
        }
        sort(a.begin(), a.end(), cmp);

        int r = n-1;
        ll prod = 1;

        if (pos == 0) {
            if (containsZero) {
                prod = 0;
            } else {
                for (int i=0; i < 5; i++) {
                    prod = prod*a[i];
                }
            }
        } else {
            for (int c=0; c < 4; c++) {
               prod = prod*a[r--];
            }
            int l = r;
            bool findPos = prod >= 0;
            while (l >= 0) {
                ll p = prod;
                int c = a[l];
                for (int i = r+1; i < n; i++) {
                    ll x = prod * c / a[i];
                    p = max(p, x);
                }
                prod = max(p, prod);
                l--;
            }
        }
        cout<<prod<<"\n";
    }
    return 0;
}


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

bool cmp(int a, int b) {
    return abs(a) < abs(b);
}
int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        int pos = 0;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
            if (a[i] > 0) pos++;
        }
        sort(a.begin(), a.end(), cmp);

        // for (int i=0; i < n; i++) cout<<a[i]<<" ";
        // cout<<endl;

        int r = n-1;
        ll prod = 1;

        if (pos == 0) {
            if (containsZero) {
                prod = 0;
            } else {
                for (int i=0; i < 5; i++) {
                    prod = prod*a[i];
                }
            }
        } else {
            for (int c=0; c < 5; c++) {
               prod = prod*a[r--];
            }
            int l = r;
            ll res = prod;
            while (l >= 0) {
                int c = a[l];
                for (int i = r+1; i < n; i++) {
                    if (a[i] != 0) {
                        ll x = (prod / a[i]) * c;
                        res = max(res, x);
                    }
                }
                l--;
            }
            prod = res;
        }
        cout<<prod<<"\n";
    }
    return 0;
}

// 0 5 -4 4 4 1 -3 3 3
// 0 1 3 -3 3 -4 4 4 5


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
        }
        sort(a.begin(), a.end());

        ll res = 1;
        vi els;
        for (int i=0; i < n; i++) {
            if (i < 5 || n - i - 1 < n - 5) {
                els.push_back(a[i]);
            }
        }

        int l = els.size();
        ll prod = INT_MIN;
        if (containsZero) prod = 0;
        for (int i=0; i < l; i++) {
            for (int j=i+1; j < l; j++) {
                for (int k=j+1; k < l; k++) {
                    for (int m=k+1; m < l; m++) {
                        for (int o=m+1; o < l; o++) {
                            ll r = (long) els[i]*els[j]*els[k]*els[m]*els[o];
                            prod = max(prod, r);
                        }
                    }
                }
            }
        }

        cout<<prod<<"\n";

    }
    return 0;
}

// -3 -2 -1 -1 1 2


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

bool cmp(int a, int b) {
    return abs(a) < abs(b);
}
int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int containsZero = false;
        int pos = 0;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] == 0) containsZero = true;
            if (a[i] > 0) pos++;
        }
        sort(a.begin(), a.end(), cmp);

        // for (int i=0; i < n; i++) cout<<a[i]<<" ";
        // cout<<"\n";

        int r = n-1;
        ll prod = 1;

        if (pos == 0) {
            for (int i=0; i < 5; i++) {
                prod = prod*a[i];
            }
        } else {
            for (int c=0; c < 4; c++) {
               prod = prod*a[r--];
            }
            int l = r;
            bool findPos = prod >= 0;
            while (l >= 0) {
                ll p = prod;
                int c = a[l];
                for (int i = r+1; i < n; i++) {
                    ll x = prod * c / a[i];
                    p = max(p, x);
                }
                prod = max(p, prod);
                l--;
            }
        }
        cout<<prod<<"\n";
    }
    return 0;
}

// -3 -2 -1 -1 1 2


/*
*  Problem Link: https://codeforces.com/contest/1406/problem/B
*  Author: Raunak Sett
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>

int main() {
    IOS
    // Code Here
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        vi a(n);

        int negs = 0;
        int pos = 0;
        int containsZero = false;
        int maxNegIdx = -1;
        int maxNeg = INT_MAX;
        // Take Input
        for (int i=0; i < n; i++) {
            cin>>a[i];
            if (a[i] < 0) {
                negs++;
            }
            else if (a[i] > 0) pos++;
            else containsZero = true;
        }
        sort(a.begin(), a.end());

        int res = 1;
        // If All Negatives or zero
        if (pos == 0) {
            if (containsZero) res = 0;
            else {
                int r = n-1;
                int c = 0;
                int prod = 1;
                while (c < 5) {
                    c++;
                    prod = prod * a[r];
                    r--;
                }
                res = prod;
            }
        } else {
            if (negs == 0) {
                int i = n-1;
                int c = 0;
                int prod = 1;
                while (c < 5) {
                    prod = prod * a[i];
                    i--;
                    c++;
                }
                res = prod;
            } else {
                int c = 0;
                int l = 0;
                int r = n - 1;
                int prod = 1;
                while (c < 5) {
                    int negProd = a[l]*a[l+1];
                    if (negProd > a[r]) {
                        prod = prod*negProd;
                        l += 2;
                        c += 2;
                    } else {
                        prod = prod*a[r];
                        r--;
                        c++;
                    }
                }
                res = prod;
            }
        }

        cout<<res<<"\n";

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, n;
long long a[500005];

void prt(long long *v, int n) {
	for(int i=0;i<n;i++) { printf("%lld ", v[i]); }
	putchar('\n');
}

struct cmp {
	inline bool operator()(long long x, long long y) const {
		return llabs(x) > llabs(y);
	}
};

int main() {
	cin>>t;
	while(t--) {
		cin>>n;
		for(int i=0;i<n;i++) cin>>a[i];
		sort(a, a+n, cmp());
		//prt(a, n);
		long long ans = a[0]*a[1]*a[2]*a[3]*a[4];
		for(int i=0;i<5;i++) { // replace a[i] with the other n-1 candidates
			long long tmp = 1;
			for(int j=0;j<5;j++) if(j!=i) tmp *= a[j];
			for(int j=5;j<n;j++) if(tmp*a[j] > ans) ans = tmp*a[j];
		}
		//tmp = a[0]*a[1]*a[2]*a[3]; s.insert(0); s.insert(1); s.insert(2); s.insert(3);
		//for(int i=0;i<n;i++) if(!s.count(i) && tmp*a[i] > ans) ans = tmp * a[i];
		//tmp = a[0]*a[1]*a[2]*a[4]; s.erase(3); s.insert(4);
		//for(int i=0;i<n;i++) if(!s.count(i) && tmp*a[i] > ans) ans = tmp * a[i];
		//tmp = a[0]*a[1]*a[3]*a[4]; s.erase(2); s.insert(3);
		//for(int i=0;i<n;i++) if(!s.count(i) && tmp*a[i] > ans) ans = tmp * a[i];
		//tmp = a[0]*a[2]*a[3]*a[4]; s.erase(1); s.insert(2);
		//for(int i=0;i<n;i++) if(!s.count(i) && tmp*a[i] > ans) ans = tmp * a[i];
		//tmp = a[1]*a[2]*a[3]*a[4]; s.erase(0); s.insert(1);
		//for(int i=0;i<n;i++) if(!s.count(i) && tmp*a[i] > ans) ans = tmp * a[i];
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, n;
long long a[500005];
bool hasZero, hasPositive;

void prt(long long *v, int n) {
	for(int i=0;i<n;i++) { printf("%lld ", v[i]); }
	putchar('\n');
}

struct cmp {
	inline bool operator()(long long x, long long y) const {
		return llabs(x) > llabs(y);
	}
};

int main() {
	cin>>t;
	while(t--) {
		cin>>n;
		hasZero = hasPositive = false;
		for(int i=0;i<n;i++) {
			cin>>a[i];
			if(a[i]==0) hasZero = true;
			if(a[i]>0)  hasPositive = true;
		}
		sort(a, a+n, cmp());
		//prt(a, n);
		long long ans = -1e18;
		if(!hasPositive) { // try 5 largest negative number
			long long tmp = 1;
			int k = 5;
			for(int i=n-1;i>=0 && k;i--) {
				if(a[i]==0) continue;
				tmp *= a[i];
				k--;
			}
			if(k==0 && tmp>ans) ans = tmp;
		}
		if(hasZero && 0>ans) ans = 0; // try 0
		for(int i=0;i<5;i++) { // replace a[i] with the other n-5 candidates
			long long tmp = 1;
			for(int j=0;j<5;j++) if(j!=i) tmp *= a[j];
			for(int j=5;j<n;j++) if(tmp*a[j] > ans) ans = tmp*a[j];
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, n;
long long a[500005];
bool hasZero, hasPositive;

void prt(long long *v, int n) {
	for(int i=0;i<n;i++) { printf("%lld ", v[i]); }
	putchar('\n');
}

struct cmp {
	inline bool operator()(long long x, long long y) const {
		return llabs(x) > llabs(y);
	}
};

int main() {
	cin>>t;
	while(t--) {
		cin>>n;
		hasZero = hasPositive = false;
		for(int i=0;i<n;i++) {
			cin>>a[i];
			if(a[i]==0) hasZero = true;
			if(a[i]>0)  hasPositive = true;
		}
		sort(a, a+n, cmp());
		//prt(a, n);
		long long ans = a[0]*a[1]*a[2]*a[3]*a[4];
		if(!hasPositive) { // try 5 largest negative number
			long long tmp = 1;
			int k = 5;
			for(int i=n-1;i>=0 && k;i--) {
				if(a[i]==0) continue;
				tmp *= a[i];
				k--;
			}
			if(k==0 && tmp>ans) ans = tmp;
		}
		if(hasZero && 0>ans) ans = 0; // try 0
		for(int i=0;i<5;i++) { // replace a[i] with the other n-5 candidates
			long long tmp = 1;
			for(int j=0;j<5;j++) if(j!=i) tmp *= a[j];
			for(int j=5;j<n;j++) if(tmp*a[j] > ans) ans = tmp*a[j];
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, n;
long long a[250005]; // positive
long long b[250005]; // negative

void prt(int *v, int n) {
	for(int i=0;i<n;i++) { printf("%d ", v[i]); }
	putchar('\n');
}

int main() {
	cin>>t;
	while(t--) {
		cin>>n;
		if(n==5) {
			long long ans = 1, x;
			for(int i=0;i<5;i++) {
				cin>>x;
				ans *= x;
			}
			printf("%d\n", ans);
			continue;
		}
		int p1 = 0, p2 = 0;
		bool has0 = false;
		for(int i=0;i<n;i++) {
			int x; cin>>x;
			if(x==0) has0 = true;
			else if(x>0) a[p1++] = x;
			else b[p2++] = x;
		}
		sort(a, a+p1);
		sort(b, b+p2);
		for(int i=0;i<p2;i++) assert(b[i]!=0);
		long long ans = -2e18; // wtf
		long long tmp;
		// zero
		if(has0 && 0>ans) ans = 0;
		// positives
		if(p1>=5) {
			tmp = a[p1-1]*a[p1-2]*a[p1-3]*a[p1-4]*a[p1-5];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=3 && p2>=2) {
			tmp = a[p1-1]*a[p1-2]*a[p1-3]*b[0]*b[1];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=1 && p2>=4) {
			tmp = a[p1-1]*b[0]*b[1]*b[2]*b[3];
			if(tmp > ans) ans = tmp;
		}
		// negatives
		if(p1==0 && p2>=5) {
			tmp = b[p2-1]*b[p2-2]*b[p2-3]*b[p2-4]*b[p2-5];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=2 && p2>=3) {
			tmp = a[0]*a[1]*b[p2-1]*b[p2-2]*b[p2-3];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=4 && p2>=1) {
			tmp = a[0]*a[1]*a[2]*a[3]*b[p2-1];
			if(tmp > ans) ans = tmp;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t, n;
int a[100005]; // positive
int b[100005]; // negative

void prt(int *v, int n) {
	for(int i=0;i<n;i++) { printf("%d ", v[i]); }
	putchar('\n');
}

int main() {
	cin>>t;
	while(t--) {
		cin>>n;
		if(n==5) {
			int ans = 1, x;
			for(int i=0;i<5;i++) {
				cin>>x;
				ans *= x;
			}
			printf("%d\n", ans);
			continue;
		}
		int p1 = 0, p2 = 0;
		bool has0 = false;
		for(int i=0;i<n;i++) {
			int x; cin>>x;
			if(x==0) has0 = true;
			if(x>0) a[p1++] = x;
			else b[p2++] = x;
		}
		sort(a, a+p1);
		sort(b, b+p2);
		long long ans = -2e18; // wtf
		long long tmp;
		// zero
		if(has0 && 0>ans) ans = 0;
		// positives
		if(p1>=5) {
			tmp = a[p1-1]*a[p1-2]*a[p1-3]*a[p1-4]*a[p1-5];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=3 && p2>=2) {
			tmp = a[p1-1]*a[p1-2]*a[p1-3]*b[0]*b[1];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=1 && p2>=4) {
			tmp = a[p1-1]*b[0]*b[1]*b[2]*b[3];
			if(tmp > ans) ans = tmp;
		}
		// negatives
		if(p1==0 && p2>=5) {
			tmp = b[p2-1]*b[p2-2]*b[p2-3]*b[p2-4]*b[p2-5];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=2 && p2>=3) {
			tmp = a[0]*a[1]*b[p2-1]*b[p2-2]*b[p2-3];
			if(tmp > ans) ans = tmp;
		}
		if(p1>=4 && p2>=1) {
			tmp = a[0]*a[1]*a[2]*a[3]*b[p2-1];
			if(tmp > ans) ans = tmp;
		}
		cout<<ans<<endl;
	}
	return 0;
}


/*
 * Remember a 6.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience.
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.text.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=1000000000+7;//10^9+7
	private static final int N=100000+7; //10^5+7
	private static final double EPS=1e-9;
//	private static final int LIM=26;
//	private static final double PI=3.1415;
//	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static int color[]=new int[N];
	private static boolean mark[]=new boolean[N];
//	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//	private static ArrayList<Pair> v[]=new ArrayList[N];
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
//	private static <E extends Comparable> E min(E a,E b){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static <E extends Comparable> E min(E a,E b,E c){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static void shuffle(long [] arr) {
//		for (int i = arr.length - 1; i >= 2; i--) {
//			int x = new Random().nextInt(i - 1);
//	        long temp = arr[x];
//	        arr[x] = arr[i];
//	        arr[i] = temp;
//	    }
//	 }
//	private static long gcd(long a, long b){
//		if(b==0)return a;
//		return gcd(b,a%b);
//	}
//	private static boolean check(int x,int y){
//		if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//		return false;
//	}
//	static class Node{
//		int left;
//		int right;
//		Node(){
//			left=0;
//			right=0;
//		}
//	}
	static long ar[],cnt=0;
	static ArrayList<Pair> v[]=new ArrayList[N];
	public static void dfs(int node,boolean flag,long val){
		mark[node]=true;
		for(Pair pair:v[node]){
			if(!mark[pair.l]){
				if(val>ar[node]||flag)dfs(pair.l,true,max(0,val+pair.r));
				else dfs(pair.l,false,max(0,val+pair.r));
			}
		}
		if(val>ar[node]||flag)cnt++;
	}
	public static void main(String[] args) throws IOException{
		int n=in.nextInt();
		ar=new long[n+1];
		for(int i=1;i<=n;i++)
			ar[i]=in.nextLong();
		int p,c;
		for(int i=1;i<=n;i++)
			v[i]=new ArrayList();
		for(int i=1;i<n;i++){
			p=in.nextInt();
			c=in.nextInt();
			v[i+1].add(new Pair(p,c));
			v[p].add(new Pair(i+1,c));
		}
		dfs(1,false,0);
		out.println(cnt);
	}
	static class Pair<T> implements Comparable<Pair>{
		int l;
		int r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(int k,int v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o) {
			if(o.l!=l)return (int) (l-o.l);
			else return (int)(r-o.r);
		}

	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {

                	st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/*
 * Remember a 6.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience.
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.text.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=1000000000+7;//10^9+7
	private static final int N=100000+7; //10^5+7
	private static final double EPS=1e-9;
//	private static final int LIM=26;
//	private static final double PI=3.1415;
//	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static int color[]=new int[N];
	private static boolean mark[]=new boolean[N];
//	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	private static ArrayList<Pair> v[]=new ArrayList[N];
	static int ar[],cnt=0;
	private static void dfs(int node,long total){
		mark[node]=true;
		for(Pair x:v[node]){
			if(!mark[x.l]){
				dfs(x.l,total+x.r);
			}
		}
		if(total>ar[node])cnt++;
	}
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
//	private static <E extends Comparable> E min(E a,E b){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static <E extends Comparable> E min(E a,E b,E c){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static void shuffle(long [] arr) {
//		for (int i = arr.length - 1; i >= 2; i--) {
//			int x = new Random().nextInt(i - 1);
//	        long temp = arr[x];
//	        arr[x] = arr[i];
//	        arr[i] = temp;
//	    }
//	 }
//	private static long gcd(long a, long b){
//		if(b==0)return a;
//		return gcd(b,a%b);
//	}
//	private static boolean check(int x,int y){
//		if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//		return false;
//	}
//	static class Node{
//		int left;
//		int right;
//		Node(){
//			left=0;
//			right=0;
//		}
//	}
	public static void main(String[] args) throws IOException{
		int n=in.nextInt();
		ar=new int[n+1];
		for(int i=1;i<=n;i++)
			ar[i]=in.nextInt();
		for(int i=1;i<=n;i++)
			v[i]=new ArrayList();
		int p,c;
		for(int i=1;i<=8;i++){
			p=in.nextInt();
			c=in.nextInt();
			v[p].add(new Pair(i+1,c));
		}
		dfs(1,0);
		out.println(cnt);
	}
	static class Pair<T> implements Comparable<Pair>{
		int l;
		int r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(int k,int v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o) {
			if(o.l!=l)return (int) (l-o.l);
			else return (int)(r-o.r);
		}

	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {

                	st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


/*
 * Remember a 6.0 student can know more than a 10.0 student.
 * Grades don't determine intelligence, they test obedience.
 * I Never Give Up.
 * I will become Candidate Master.
 * I will defeat Saurabh Anand.
 * Skills are Cheap,Passion is Priceless.
 */
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.text.*;

import static java.lang.System.out;
import static java.util.Arrays.*;
import static java.lang.Math.*;
public class ContestMain {
	private static Reader in=new Reader();
	private static StringBuilder ans=new StringBuilder();
	private static long MOD=1000000000+7;//10^9+7
	private static final int N=100000+7; //10^5+7
	private static final double EPS=1e-9;
//	private static final int LIM=26;
//	private static final double PI=3.1415;
//	private static ArrayList<Integer> v[]=new ArrayList[N];
//	private static int color[]=new int[N];
	private static boolean mark[]=new boolean[N];
//	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//	private static ArrayList<Pair> v[]=new ArrayList[N];
	private static long powmod(long x,long n){
		if(n==0||x==0)return 1;
		else if(n%2==0)return(powmod((x*x)%MOD,n/2));
		else return (x*(powmod((x*x)%MOD,(n-1)/2)))%MOD;
	}
//	private static <E extends Comparable> E min(E a,E b){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static <E extends Comparable> E min(E a,E b,E c){
//		if(a.compareTo(b)>=0)return b;
//		else return a;
//	}
//	private static void shuffle(long [] arr) {
//		for (int i = arr.length - 1; i >= 2; i--) {
//			int x = new Random().nextInt(i - 1);
//	        long temp = arr[x];
//	        arr[x] = arr[i];
//	        arr[i] = temp;
//	    }
//	 }
//	private static long gcd(long a, long b){
//		if(b==0)return a;
//		return gcd(b,a%b);
//	}
//	private static boolean check(int x,int y){
//		if((x>=0&&x<n)&&(y>=0&&y<m)&&mat[x][y]!='X'&&!visited[x][y])return true;
//		return false;
//	}
//	static class Node{
//		int left;
//		int right;
//		Node(){
//			left=0;
//			right=0;
//		}
//	}
	static long ar[],cnt=0;
	static ArrayList<Pair> v[]=new ArrayList[N];
	public static void dfs(int node,boolean flag,long val){
		mark[node]=true;
		for(Pair pair:v[node]){
			if(!mark[pair.l]){
				if(val>ar[node]||flag)dfs(pair.l,true,val+pair.r);
				else dfs(pair.l,false,val+pair.r);
			}
		}
		if(val>ar[node]||flag)cnt++;
	}
	public static void main(String[] args) throws IOException{
		int n=in.nextInt();
		ar=new long[n+1];
		for(int i=1;i<=n;i++)
			ar[i]=in.nextLong();
		int p,c;
		for(int i=1;i<=n;i++)
			v[i]=new ArrayList();
		for(int i=1;i<n;i++){
			p=in.nextInt();
			c=in.nextInt();
			v[p].add(new Pair(i+1,c));
		}
		dfs(1,false,0);
		out.println(cnt);
	}
	static class Pair<T> implements Comparable<Pair>{
		int l;
		int r;
		Pair(){
			l=0;
			r=0;
		}
		Pair(int k,int v){
			l=k;
			r=v;
		}
		@Override
		public int compareTo(Pair o) {
			if(o.l!=l)return (int) (l-o.l);
			else return (int)(r-o.r);
		}

	}
	static class Reader{
        BufferedReader br;
        StringTokenizer st;
        public Reader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {

                	st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static long d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		dfs(1,0);
		int count=0;
		for(int i=1;i<n+1;i++){
			if(!g[i].vis)
				count++;
		}
		System.out.println(count);
	}

	private static void dfs(int s, int dis){
		if(s!=1 && dis > Integer.parseInt(ver[s-1]))
			return ;
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis)
				dfs(e.v,dis + e.w);
		}
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static long d[];
	static 	boolean vis[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

	  vis =  new boolean[n+1];
		dfs2(1);

/*		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i] && par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])){

					break;
				}

				u=v;
			}
		}
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}
		for(int i=1;i<=n;i++)
			if(vis[i])
				System.out.println(i);
		*/

		int count=0;
		dfs3(1);
		for(int i=1;i<n+1;i++){
			if(g[i].vis)
				count++;
		}
		System.out.println(count);
	}

	private static void dfs3(int s){
		if(vis[s])
			return;
		g[s].vis=false;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(g[e.v].vis){
				dfs3(e.v);
			}
		}
	}

	private static void dfs2(int s){

		int v = s;
		int u=s;
		while(!vis[s] && par[u]!=0){
			v = par[u];

			if(d[s] - d[v] > Integer.parseInt(ver[s-1])){
				vis[s] = true;
				return;
			}
			u=v;
		}

		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if( par[s]!=e.v){
				dfs2(e.v);
			}
		}

	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static int d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new int[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1]) || vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1]) || vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs(int s, int dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[],count;
	static long d[];
	static 	boolean vis[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

	    vis =  new boolean[n+1];
		dfs2(1);

		 count=0;
		dfs3(1);

		System.out.println(n-count);
	}

	private static void dfs3(int s){
		if(vis[s])
			return;
		g[s].vis=false;
		count++;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(g[e.v].vis){
				dfs3(e.v);
			}
		}
	}

	private static void dfs2(int s){

		int v = s;
		int u=s;
		while(!vis[s] && par[u]!=0){
			v = par[u];

			if(d[s] - d[v] > Integer.parseInt(ver[s-1])){
				vis[s] = true;
				return;
			}
			u=v;
		}

		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if( par[s]!=e.v){
				dfs2(e.v);
			}
		}

	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[],count;
	static long d[];
	static 	boolean vis[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];

	    vis =  new boolean[n+1];
		dfs2(1,0);

		 count=0;
		dfs3(1);

		System.out.println(n-count);
	}

	private static void dfs3(int s){
		if(vis[s])
			return;
		g[s].vis=true;
		count++;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				dfs3(e.v);
			}
		}
	}

	private static void dfs2(int s,long dis){

		int v = s;
		int u=s;
		d[s]=dis;
		while(!vis[s] && par[u]!=0){
			v = par[u];

			if(d[s] - d[v] > Integer.parseInt(ver[s-1])){
				vis[s] = true;
				return;
			}
			u=v;
		}

		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if( par[s]!=e.v){
				par[e.v] =s;
				dfs2(e.v,dis+e.w);
			}
		}

	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[],count;
	static long d[];
	static 	boolean vis[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		 count=0;
	    vis =  new boolean[n+1];
		dfs2(1,0);

		System.out.println(n-count);
	}

	private static void dfs2(int s,long dis){

		int v = s;
		int u=s;
		d[s]=dis;
		while(!vis[s] && par[u]!=0){
			v = par[u];

			if(d[s] - d[v] > Integer.parseInt(ver[s-1])){
				vis[s] = true;
				return;
			}
			u=v;
		}
		count++;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if( par[s]!=e.v){
				par[e.v] =s;
				dfs2(e.v,dis+e.w);
			}
		}

	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static long d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])){
					dfs2(i,vis);
					break;
				}

				u=v;
			}
		}
	/*	for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}*/

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs2(int s, boolean vis[]){
		vis[s]=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!vis[e.v]&& par[s]!=e.v){
				dfs2(e.v,vis);
			}
		}

	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static long d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i] && par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])){
					dfs2(i,vis);
					break;
				}

				u=v;
			}
		}
	/*	for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}*/

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs2(int s, boolean vis[]){
		vis[s]=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!vis[e.v]&& par[s]!=e.v){
				dfs2(e.v,vis);
			}
		}

	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static long d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])||vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs(int s, long dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static int d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new int[n+1];
		dfs(1,0);
		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1]) || vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i])
				count++;
		}
		System.out.println(count);
	}

	private static void dfs(int s, int dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[],count;
	static long d[];
	static 	boolean vis[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new long[n+1];
		 count=0;
	    vis =  new boolean[n+1];
		dfs2(1,0,0);

		System.out.println(n-count);
	}

	private static void dfs2(int s,long dis,long sum){
		d[s]=dis;
		/*	int v = s;
		int u=s;

		while(!vis[s] && par[u]!=0){
			v = par[u];

			if(d[s] - d[v] > Integer.parseInt(ver[s-1])){
				vis[s] = true;
				return;
			}
			u=v;
		}*/

		if(dis>0)
			sum=dis;
		else{
			sum=0;
			dis=0;
		}
		if(sum> Integer.parseInt(ver[s-1])){
			vis[s] = true;
			return;
		}
		count++;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if( par[s]!=e.v){
				par[e.v] =s;
				dfs2(e.v,dis+e.w,sum);
			}
		}

	}

	private static class Graph{
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.io.*;
import java.util.*;
public class AlyonaTree {
	static Graph g[];
	static String ver[];
	static int par[];
	static int d[];
	public static void main(String args[]) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		 ver=br.readLine().split(" ");
		g= new Graph[n+1];
		for(int i=1;i<n+1;i++){
			g[i]= new Graph();
		}
		for(int i=2;i<=n;i++){
			String s[]=br.readLine().split(" ");
			g[i].al.add(new edge(Integer.parseInt(s[0]), Integer.parseInt(s[1])));
			g[Integer.parseInt(s[0])].al.add(new edge(i, Integer.parseInt(s[1])));
		}
		par=new int[n+1];
		d=new int[n+1];
		dfs(1,0);

		boolean vis[]= new boolean[n+1];
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(par[u]!=0){
				v = par[u];

				if(d[i] - d[v] > Integer.parseInt(ver[i-1])){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}
		for(int i=2;i<n+1;i++){
			int v = i;
			int u=i;
			while(!vis[i]&&par[u]!=0){
				v = par[u];

				if(vis[v]){
					vis[i]=true;
					break;
				}

				u=v;
			}
		}

		int count=0;
		for(int i=1;i<n+1;i++){
			if(vis[i]){
				count++;
			//	System.out.println(i);
			}
		}
		System.out.println(count);
	}

	private static void dfs(int s, int dis){
		g[s].vis=true;
		for(int i=0;i<g[s].al.size();i++){
			edge e = g[s].al.get(i);
			if(!g[e.v].vis){
				par[e.v] =s;
				dfs(e.v,dis + e.w);
			}
		}
		d[s]=dis;
	}

	private static class Graph{
		boolean vis=false;
		ArrayList<edge> al = new ArrayList<edge>();
	}
	private static class edge{
		int v;
		int w;
		public edge(int v, int w){
			this.v=v;
			this.w=w;
		}
	}
}


import java.awt.*;
import java.io.*;
import java.util.*;

public class Abc {
    static int n;
    static int arr[];
    static int cnt[];
    static ArrayList<Integer> adj[];
    static Map<Point,Integer> map;
    static int ans=0;
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        n=sc.nextInt();
        adj=new ArrayList[n];
        for (int i=0;i<n;i++){
            adj[i]=new ArrayList<>();
        }
        map=new HashMap<>();
        arr=new int[n];
        cnt=new int[n];
        for (int i=0;i<n;i++)arr[i]=sc.nextInt();
        for (int i=0;i<n-1;i++){
            int p=sc.nextInt()-1;
            adj[i+1].add(p);
            adj[p].add(i+1);
            int c=sc.nextInt();
            map.put(new Point(i+1,p),c);
            map.put(new Point(p,i+1),c);
        }
        dfs(0,0);
        dfs1(0,0,0);
        System.out.println(ans);
    }
    static void dfs1(int v,int par,long dis){
        if (dis>arr[v]){
            ans+=cnt[v];
            return;
        }
        for (int u:adj[v]){
            if (u!=par){
                dfs1(u,v,dis+map.get(new Point(u,v)));
            }
        }
    }
    static void dfs(int v,int par){
        for (int u:adj[v]){
            if (u!=par){
                dfs(u,v);
                cnt[v]+=cnt[u];
            }
        }
        cnt[v]++;

    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.awt.*;
import java.io.*;
import java.util.*;

public class Abc {
    static int n;
    static int arr[];
    static int cnt[];
    static ArrayList<Integer> adj[];
    static Map<Point,Integer> map;
    static int ans=0;
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        n=sc.nextInt();
        adj=new ArrayList[n];
        for (int i=0;i<n;i++){
            adj[i]=new ArrayList<>();
        }
        map=new HashMap<>();
        arr=new int[n];
        cnt=new int[n];
        for (int i=0;i<n;i++)arr[i]=sc.nextInt();
        for (int i=0;i<n-1;i++){
            int p=sc.nextInt()-1;
            adj[i+1].add(p);
            adj[p].add(i+1);
            int c=sc.nextInt();
            map.put(new Point(i+1,p),c);
            map.put(new Point(p,i+1),c);
        }
        dfs(0,0);
        dfs1(0,0,0,0);
        System.out.println(ans);
    }
    static void dfs1(int v,int par,long dis,long sum){
        if (sum-dis>arr[v]){
            ans+=cnt[v];
            return;
        }
        for (int u:adj[v]){
            if (u!=par){
                dfs1(u,v,Math.min(sum+map.get(new Point(u,v)),dis),sum+map.get(new Point(u,v)));
            }
        }
    }
    static void dfs(int v,int par){
        for (int u:adj[v]){
            if (u!=par){
                dfs(u,v);
                cnt[v]+=cnt[u];
            }
        }
        cnt[v]++;

    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class _Alyona_and_the_Trees {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		String[] sr = br.readLine().split(" ");
		ArrayList<ArrayList<pair>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sr[i]);

		}
		for (int i = 0; i < n; i++) {
			graph.add(new ArrayList<>());
		}
		boolean[] art = new boolean[n];
		for (int i = 1; i <= n-1; i++) {
			sr = br.readLine().split(" ");
			int val = Integer.parseInt(sr[0]) - 1;
			long wt = Integer.parseInt(sr[1]);
			pair p = new pair(val, wt);
			graph.get(i).add(p);
			graph.get(val).add(new pair(i, wt));
		}
		dfs(0, -1, graph, 0,0, art, arr);
		int[] dp = new int[n];
		dfs2(0, -1, graph, dp);
		int c=0;
		for(int i=0;i<n;i++){
			if(art[i]){
				c+=dp[i];
			}
		}
		System.out.println(c);
	}

	public static void dfs(int v, int par, ArrayList<ArrayList<pair>> graph, long dist, long min, boolean[] arr,
			int[] values) {
			if (dist - min > values[v]) {
				arr[v] = true;
				return;
			}
		for (pair p : graph.get(v)) {
			if (p.vert == par) {
				continue;
			}

			dfs(p.vert, v, graph, dist+p.weight, Math.min(dist + p.weight, min), arr, values);

		}

	}

	public static int dfs2(int v, int p, ArrayList<ArrayList<pair>> graph, int[] dp) {
		int c = 0;
		for (pair ver : graph.get(v)) {
			if (ver.vert == p) {
				continue;
			}
			c += dfs2(ver.vert, v, graph, dp);
		}
		return dp[v]=c + 1;
	}

	public static class pair {
		int vert;
		long weight;

		pair(int val, long weight) {
			this.vert = val;
			this.weight = weight;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class _Alyona_and_the_Trees {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		String[] sr = br.readLine().split(" ");
		ArrayList<ArrayList<pair>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sr[i]);

		}
		for (int i = 0; i < n; i++) {
			graph.add(new ArrayList<>());
		}
		boolean[] art = new boolean[n];
		for (int i = 1; i <= n-1; i++) {
			sr = br.readLine().split(" ");
			int val = Integer.parseInt(sr[0]) - 1;
			int wt = Integer.parseInt(sr[1]);
			pair p = new pair(val, wt);
			graph.get(i).add(p);
			graph.get(val).add(new pair(i, wt));
		}
		dfs(0, -1, graph, 0,0, art, arr);
		int[] dp = new int[n];
		dfs2(0, -1, graph, dp);
		int c=0;
		for(int i=0;i<n;i++){
			if(art[i]){
				c+=dp[i];
			}
		}
		System.out.println(c);
	}

	public static void dfs(int v, int par, ArrayList<ArrayList<pair>> graph, long dist, long min, boolean[] arr,
			int[] values) {
		if (min != Integer.MAX_VALUE) {
			if (dist - min >= values[v]) {
				arr[v] = true;
				return;
			}
		}
		for (pair p : graph.get(v)) {
			if (p.vert == par) {
				continue;
			}

			dfs(p.vert, v, graph, dist+p.weight, Math.min(dist + p.weight, min), arr, values);

		}

	}

	public static int dfs2(int v, int p, ArrayList<ArrayList<pair>> graph, int[] dp) {
		int c = 0;
		for (pair ver : graph.get(v)) {
			if (ver.vert == p) {
				continue;
			}
			c += dfs2(ver.vert, v, graph, dp);
		}
		return dp[v]=c + 1;
	}

	public static class pair {
		int vert;
		int weight;

		pair(int val, int weight) {
			this.vert = val;
			this.weight = weight;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class _Alyona_and_the_Trees {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		String[] sr = br.readLine().split(" ");
		ArrayList<ArrayList<pair>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sr[i]);

		}
		for (int i = 0; i < n; i++) {
			graph.add(new ArrayList<>());
		}
		boolean[] art = new boolean[n];
		for (int i = 1; i <= n-1; i++) {
			sr = br.readLine().split(" ");
			int val = Integer.parseInt(sr[0]) - 1;
			long wt = Integer.parseInt(sr[1]);
			pair p = new pair(val, wt);
			graph.get(i).add(p);
			graph.get(val).add(new pair(i, wt));
		}
		dfs(0, -1, graph, 0,0, art, arr);
		int[] dp = new int[n];
		dfs2(0, -1, graph, dp);
		int c=0;
		for(int i=0;i<n;i++){
			if(art[i]){
				c+=dp[i];
			}
		}
		System.out.println(c);
	}

	public static void dfs(int v, int par, ArrayList<ArrayList<pair>> graph, long dist, long min, boolean[] arr,
			int[] values) {
			if (dist - min >= values[v]) {
				arr[v] = true;
				return;
			}
		for (pair p : graph.get(v)) {
			if (p.vert == par) {
				continue;
			}

			dfs(p.vert, v, graph, dist+p.weight, Math.min(dist + p.weight, min), arr, values);

		}

	}

	public static int dfs2(int v, int p, ArrayList<ArrayList<pair>> graph, int[] dp) {
		int c = 0;
		for (pair ver : graph.get(v)) {
			if (ver.vert == p) {
				continue;
			}
			c += dfs2(ver.vert, v, graph, dp);
		}
		return dp[v]=c + 1;
	}

	public static class pair {
		int vert;
		long weight;

		pair(int val, long weight) {
			this.vert = val;
			this.weight = weight;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class _Alyona_and_the_Trees {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		String[] sr = br.readLine().split(" ");
		ArrayList<ArrayList<pair>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(sr[i]);

		}
		for (int i = 0; i < n; i++) {
			graph.add(new ArrayList<>());
		}
		boolean[] art = new boolean[n];
		for (int i = 1; i <= n-1; i++) {
			sr = br.readLine().split(" ");
			int val = Integer.parseInt(sr[0]) - 1;
			int wt = Integer.parseInt(sr[1]);
			pair p = new pair(val, wt);
			graph.get(i).add(p);
			graph.get(val).add(new pair(i, wt));
		}
		dfs(0, -1, graph, 0,0, art, arr);
		int[] dp = new int[n];
		dfs2(0, -1, graph, dp);
		int c=0;
		for(int i=0;i<n;i++){
			if(art[i]){
				c+=dp[i];
			}
		}
		System.out.println(c);
	}

	public static void dfs(int v, int par, ArrayList<ArrayList<pair>> graph, int dist, int min, boolean[] arr,
			int[] values) {
		if (min != Integer.MAX_VALUE) {
			if (dist - min >= values[v]) {
				arr[v] = true;
				return;
			}
		}
		for (pair p : graph.get(v)) {
			if (p.vert == par) {
				continue;
			}

			dfs(p.vert, v, graph, dist+p.weight, Math.min(dist + p.weight, min), arr, values);

		}

	}

	public static int dfs2(int v, int p, ArrayList<ArrayList<pair>> graph, int[] dp) {
		int c = 0;
		for (pair ver : graph.get(v)) {
			if (ver.vert == p) {
				continue;
			}
			c += dfs2(ver.vert, v, graph, dp);
		}
		return dp[v]=c + 1;
	}

	public static class pair {
		int vert;
		int weight;

		pair(int val, int weight) {
			this.vert = val;
			this.weight = weight;
		}
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Myclass {
		public static ArrayList a[]=new ArrayList[200001];
		static boolean visited[]=new boolean [200001];
		static long value[];
		static long maxi[];
		static long dp[]=new long[200001];
		static long ans;
		static void dfs(pair n,int p)
		{
			visited[n.x]=true;
			dp[n.x]=Math.max(dp[p]+n.y,n.y);
			if(dp[n.x]>value[n.x])
			{
				ans++;
				return;
			}

			for(int i=0;i<a[n.x].size();i++)
			{
				pair y=(pair) a[n.x].get(i);
				if(!visited[y.x])
				{
					dfs(y,n.x);
				}
			}
		}
		public static void main(String[] args)
		{
		    InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);
			int n=in.nextInt();
			for(int i=0;i<=n;i++)
				a[i]=new ArrayList<pair>();
			value=new long[n+1];
			maxi=new long[n+1];
			for(int i=1;i<=n;i++)
				value[i]=in.nextLong();
			for(int i=2;i<=n;i++)
			{
				int x=in.nextInt();
				long y=in.nextLong();
				a[i].add(new pair(x,y));
				a[x].add(new pair(i,y));
			}
			dp[0]=0;
			value[0]=Long.MIN_VALUE;
			dfs(new pair(1,0),0);
			//pw.println(Arrays.toString(dp));
			for(int i=1;i<=n;i++)
			{
				if(!visited[i])
					ans++;
			}
			pw.println(ans);
			pw.flush();
			pw.close();
		}

		static class InputReader
		{
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}
		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}
		static class tri implements Comparable<tri> {
			int p, c, l;

			tri(int p, int c, int l) {
				this.p = p;
				this.c = c;
				this.l = l;
			}

			public int compareTo(tri o) {
				return Integer.compare(l, o.l);
			}
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}
		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}

		public static HashSet<Integer> primeFactorization(int n)
		{
			HashSet<Integer> a =new HashSet<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x%M*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result%M * x%M)%M;
		        x=(x%M * x%M)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		 public static long[] shuffle(long[] a, Random gen){
		        for(int i = 0, n = a.length;i < n;i++){
		            int ind = gen.nextInt(n-i)+i;
		            long d = a[i];
		            a[i] = a[ind];
		            a[ind] = d;
		        }
		        return a;
		    }
		static class pair implements Comparable<pair>
		{
			Integer x;
			Long y;
			pair(int a,long m)
			{
				this.x=a;
				this.y=m;
			}

		public boolean isEmpty() {
				// TODO Auto-generated method stub
				return false;
			}

		public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

			return result;
			}

			public String toString()
			{
				return x+" "+y;
			}

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode();
			}
		}
		static  class triplet
		{
			Long x;
			Long y;
			Long z;
			triplet(long x,long y,long z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}
		}
		static class jodi
		{
			Integer x;
			Integer y;
			jodi(int x,int y)
			{
				this.x=x;
				this.y=y;
			}
		}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.regex.*;
public class Myclass {
		public static ArrayList a[]=new ArrayList[200001];
		static boolean visited[]=new boolean [200001];
		static long value[];
		static long maxi[];
		static long dp[]=new long[200001];
		static long ans;
		static void dfs(pair n,int p)
		{
			visited[n.x]=true;
			dp[n.x]=dp[p]+n.y;
			for(int i=0;i<a[n.x].size();i++)
			{
				pair y=(pair) a[n.x].get(i);
				if(!visited[y.x])
				{
					dfs(y,n.x);
				}
			}
		}
		public static void main(String[] args)
		{
		    InputReader in = new InputReader(System.in);
			PrintWriter pw = new PrintWriter(System.out);
			int n=in.nextInt();
			for(int i=0;i<=n;i++)
				a[i]=new ArrayList<pair>();
			value=new long[n+1];
			maxi=new long[n+1];
			for(int i=1;i<=n;i++)
				value[i]=in.nextLong();
			for(int i=2;i<=n;i++)
			{
				int x=in.nextInt();
				long y=in.nextLong();
				a[i].add(new pair(x,y));
				a[x].add(new pair(i,y));
			}
			dp[0]=0;
			value[0]=Long.MIN_VALUE;
			dfs(new pair(1,0),0);
			for(int i=1;i<=n;i++)
			{
				if(dp[i]>value[i])
				{
					ans++;
						//pw.print(i+" ");
				}
			}
			pw.println(ans);
			pw.flush();
			pw.close();
		}

		static class InputReader
		{
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}
		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
		    {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}
		static class tri implements Comparable<tri> {
			int p, c, l;

			tri(int p, int c, int l) {
				this.p = p;
				this.c = c;
				this.l = l;
			}

			public int compareTo(tri o) {
				return Integer.compare(l, o.l);
			}
		}

		public String readString()
	    {
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}
		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}

		public static HashSet<Integer> primeFactorization(int n)
		{
			HashSet<Integer> a =new HashSet<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x%M*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result%M * x%M)%M;
		        x=(x%M * x%M)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		 public static long[] shuffle(long[] a, Random gen){
		        for(int i = 0, n = a.length;i < n;i++){
		            int ind = gen.nextInt(n-i)+i;
		            long d = a[i];
		            a[i] = a[ind];
		            a[ind] = d;
		        }
		        return a;
		    }
		static class pair implements Comparable<pair>
		{
			Integer x;
			Long y;
			pair(int a,long m)
			{
				this.x=a;
				this.y=m;
			}

		public boolean isEmpty() {
				// TODO Auto-generated method stub
				return false;
			}

		public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

			return result;
			}

			public String toString()
			{
				return x+" "+y;
			}

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode();
			}
		}
		static  class triplet
		{
			Long x;
			Long y;
			Long z;
			triplet(long x,long y,long z)
			{
				this.x=x;
				this.y=y;
				this.z=z;
			}
		}
		static class jodi
		{
			Integer x;
			Integer y;
			jodi(int x,int y)
			{
				this.x=x;
				this.y=y;
			}
		}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358 implements Runnable{
	static long oo = 987654321;
	static long[] val;
	static int[] mark;
	public static void main(String[] args) {
		new Thread(null, new C358(), "cool", 1<<25).start();
	}
	@Override
	public void run() {
		MyScanner scan = new MyScanner();
		int N = scan.nextInt();
		val = new long[N];
		mark = new int[N];
		for(int i=0;i<N;i++)val[i] = scan.nextLong();
		ArrayList<Edge>[] adj = new ArrayList[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayList<>();
		for(int i=0;i<N-1;i++){
			int u = scan.nextInt();
			adj[u-1].add(new Edge(u-1,i+1,scan.nextLong()));
		}

		long[] dist = new long[N];
		for(Edge e : adj[0]){
			dfs(e.v, adj, e.c, 0);
		}
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		for(int i=0;i<N;i++){
			if(mark[i]==-1){
				q.add(i);
				while(!q.isEmpty()){
					int node = q.poll();
					for(Edge e : adj[node]){
						mark[e.v] = -2;
						q.add(e.v);
					}
				}
			}
		}
		int count = 0;
		for(int i=0;i<N;i++)if(mark[i]<0)count++;
		System.out.println(count);
	}
	private static void dfs(int idx, ArrayList<Edge>[] adj, long cost, long min) {
		if(cost-min>val[idx]){
			mark[idx]=-1;return;
		}
		for(Edge e : adj[idx]){
			dfs(e.v, adj, cost+e.c, Math.min(e.c, e.c+min));
		}
	}
	private static class Edge {
		int u, v;
		long c;
		public Edge(int u, int v, long c){this.u=u;this.v=v;this.c=c;}

	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358 implements Runnable{
	static long oo = 987654321;
	static long[] val;
	static int[] mark;
	static long[] MAX;
	public static void main(String[] args) {
		new Thread(null, new C358(), "cool", 1<<25).start();
	}
	@Override
	public void run() {
		MyScanner scan = new MyScanner();
		int N = scan.nextInt();
		val = new long[N];
		mark = new int[N];
		MAX  = new long[N];

		for(int i=0;i<N;i++)val[i] = scan.nextLong();
		ArrayList<Edge>[] adj = new ArrayList[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayList<>();
		for(int i=0;i<N-1;i++){
			int u = scan.nextInt();
			adj[u-1].add(new Edge(u-1,i+1,scan.nextLong()));
		}

		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(0);
		while(!q.isEmpty()){
			int node = q.poll();
			for(Edge e : adj[node]){
				MAX[e.v] = Math.max(MAX[node]+e.c, 0L);
				if(mark[node]!=-1&&MAX[node]+e.c<val[e.v]){
					q.add(e.v);
				}else{
					mark[e.v]=-1;
					q.add(e.v);
				}
			}
		}
		int count = 0;
		for(int i=0;i<N;i++)if(mark[i]<0)count++;
		System.out.println(count);
	}

	private static class Edge {
		int u, v;
		long c;
		public Edge(int u, int v, long c){this.u=u;this.v=v;this.c=c;}

	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358 implements Runnable{
	static long oo = 987654321;
	static long[] val;
	static int[] mark;
	static long[] MAX;
	public static void main(String[] args) {
		new Thread(null, new C358(), "cool", 1<<25).start();
	}
	@Override
	public void run() {
		MyScanner scan = new MyScanner();
		int N = scan.nextInt();
		val = new long[N];
		mark = new int[N];
		MAX  = new long[N];

		for(int i=0;i<N;i++)val[i] = scan.nextLong();
		ArrayList<Edge>[] adj = new ArrayList[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayList<>();
		for(int i=0;i<N-1;i++){
			int u = scan.nextInt();
			adj[u-1].add(new Edge(u-1,i+1,scan.nextLong()));
		}

		long[] dist = new long[N];
		for(Edge e : adj[0]){
			MAX[e.v] = Math.min(0L, MAX[e.u]+e.c);
			dfs(e.v, 0, adj, e.c);
		}
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		for(int i=0;i<N;i++){
			if(mark[i]==-1){
				q.add(i);
				while(!q.isEmpty()){
					int node = q.poll();
					for(Edge e : adj[node]){
						mark[e.v] = -2;
						q.add(e.v);
					}
				}
			}
		}
		int count = 0;
		for(int i=0;i<N;i++)if(mark[i]<0)count++;
		System.out.println(count);
	}
	private static void dfs(int idx, int par, ArrayList<Edge>[] adj, long cost) {
		if(cost+MAX[par]>val[idx]){
			mark[idx]=-1;return;
		}
		for(Edge e : adj[idx]){
			MAX[e.v] = Math.max(0L, MAX[e.u]+e.c);
			dfs(e.v, idx, adj, e.c);
		}
	}
	private static class Edge {
		int u, v;
		long c;
		public Edge(int u, int v, long c){this.u=u;this.v=v;this.c=c;}

	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358 implements Runnable{
	static long oo = 987654321;
	static long[] val;
	static int[] mark;
	static long[] MAX;
	public static void main(String[] args) {
		new Thread(null, new C358(), "cool", 1<<25).start();
	}
	@Override
	public void run() {
		MyScanner scan = new MyScanner();
		int N = scan.nextInt();
		val = new long[N];
		mark = new int[N];
		MAX  = new long[N];

		for(int i=0;i<N;i++)val[i] = scan.nextLong();
		ArrayList<Edge>[] adj = new ArrayList[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayList<>();
		for(int i=0;i<N-1;i++){
			int u = scan.nextInt();
			adj[u-1].add(new Edge(u-1,i+1,scan.nextLong()));
		}

		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(0);
		while(!q.isEmpty()){
			int node = q.poll();
			for(Edge e : adj[node]){
				MAX[e.v] = Math.max(MAX[node]+e.c, 0L);
				if(mark[node]!=-1&&MAX[node]+e.c<=val[e.v]){
					q.add(e.v);
				}else{
					mark[e.v]=-1;
					q.add(e.v);
				}
			}
		}
		int count = 0;
		for(int i=0;i<N;i++)if(mark[i]<0)count++;
		System.out.println(count);
	}

	private static class Edge {
		int u, v;
		long c;
		public Edge(int u, int v, long c){this.u=u;this.v=v;this.c=c;}

	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358 implements Runnable{
	static long oo = 987654321;
	static long[] val;
	static int[] mark;
	static long[] MIN;
	public static void main(String[] args) {
		new Thread(null, new C358(), "cool", 1<<25).start();
	}
	@Override
	public void run() {
		MyScanner scan = new MyScanner();
		int N = scan.nextInt();
		val = new long[N];
		mark = new int[N];
		MIN  = new long[N];

		for(int i=0;i<N;i++)val[i] = scan.nextLong();
		ArrayList<Edge>[] adj = new ArrayList[N];
		for(int i=0;i<N;i++)adj[i] = new ArrayList<>();
		for(int i=0;i<N-1;i++){
			int u = scan.nextInt();
			adj[u-1].add(new Edge(u-1,i+1,scan.nextLong()));
		}

		long[] dist = new long[N];
		for(Edge e : adj[0]){
			MIN[e.v] = Math.min(0L, MIN[e.u]+e.c);
			dfs(e.v, 0, adj, e.c);
		}
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		for(int i=0;i<N;i++){
			if(mark[i]==-1){
				q.add(i);
				while(!q.isEmpty()){
					int node = q.poll();
					for(Edge e : adj[node]){
						mark[e.v] = -2;
						q.add(e.v);
					}
				}
			}
		}
		int count = 0;
		for(int i=0;i<N;i++)if(mark[i]<0)count++;
		System.out.println(count);
	}
	private static void dfs(int idx, int par, ArrayList<Edge>[] adj, long cost) {
		if(cost-MIN[par]>val[idx]){
			mark[idx]=-1;return;
		}
		for(Edge e : adj[idx]){
			MIN[e.v] = Math.min(0L, MIN[e.u]+e.c);
			dfs(e.v, idx, adj, cost+e.c);
		}
	}
	private static class Edge {
		int u, v;
		long c;
		public Edge(int u, int v, long c){this.u=u;this.v=v;this.c=c;}

	}
	private static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
		String next(){
			while(st==null||!st.hasMoreElements()){
				try{st = new StringTokenizer(br.readLine());}
				catch(IOException e){e.printStackTrace();}
			}return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong(){return Long.parseLong(next());}
	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class C358_AlonyaTree {
	static ArrayList<Node> al[];
	static boolean visited[];
	static long size[];
	static long cnt;
	static boolean f[];
	static long dp[];
	static int a[];

	public static void main(String args[]) throws FileNotFoundException {
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		// StringBuilder sb = new StringBuilder();
		// ----------My Code----------

		int n = in.nextInt();
		a = new int[n];
		al = new ArrayList[n];

		dp = new long[n];
		dp[0] = 0;

		visited = new boolean[n];
		Arrays.fill(visited, false);

		f = new boolean[n];
		Arrays.fill(f, true);

		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			al[i] = new ArrayList<Node>();
		}
		for (int i = 1; i < n; i++) {
			al[in.nextInt() - 1].add(new Node(i, in.nextInt()));
		}
		size = new long[n];
		getSize(al, 0);
		cnt = 0;

		dfs(0,0);

		// cnt=0;

		out.println(cnt);

		// ---------------The End------------------

		out.close();
	}

	public static long getSize(ArrayList<Node>[] graph, int start) {
		size[start] = 1;
		for (Node neighbours : graph[start])
			size[start] += getSize(graph, neighbours.u);
		return size[start];
	}

	static void dfs(int i, long minVal) {

		if (dp[i] - minVal > a[i]) {
			cnt += size[i];
			return;
		}
		for (int j = 0; j < al[i].size(); j++) {
			int u = al[i].get(j).u;
			long val = al[i].get(j).val;
			dp[u] = dp[i] + val;
			//minVal=Math.min(minVal, dp[i]);
			dfs(u, minVal);

		}
	}

	static class Node {
		int u;
		long val;

		public Node(int u, long val) {
			super();
			this.u = u;
			this.val = val;
		}

	}
	// ---------------Extra Methods------------------

	public static long pow(long x, long n, long mod) {
		long res = 1;
		x %= mod;
		while (n > 0) {
			if (n % 2 == 1) {
				res = (res * x) % mod;
			}
			x = (x * x) % mod;
			n /= 2;
		}
		return res;
	}

	public static boolean isPal(String s) {
		for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {
			if (s.charAt(i) != s.charAt(j))
				return false;
		}
		return true;
	}

	public static String rev(String s) {
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}

	public static long gcd(long x, long y) {
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static int gcd(int x, int y) {
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static long gcdExtended(long a, long b, long[] x) {

		if (a == 0) {
			x[0] = 0;
			x[1] = 1;
			return b;
		}
		long[] y = new long[2];
		long gcd = gcdExtended(b % a, a, y);

		x[0] = y[1] - (b / a) * y[0];
		x[1] = y[0];

		return gcd;
	}

	public static int abs(int a, int b) {
		return (int) Math.abs(a - b);
	}

	public static long abs(long a, long b) {
		return (long) Math.abs(a - b);
	}

	public static int max(int a, int b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static int min(int a, int b) {
		if (a > b)
			return b;
		else
			return a;
	}

	public static long max(long a, long b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static long min(long a, long b) {
		if (a > b)
			return b;
		else
			return a;
	}
	// ---------------Extra Methods------------------

	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine() {
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n, int f) {
			if (f == 0) {
				int[] arr = new int[n];
				for (int i = 0; i < n; i++) {
					arr[i] = nextInt();
				}
				return arr;
			} else {
				int[] arr = new int[n + 1];
				for (int i = 1; i < n + 1; i++) {
					arr[i] = nextInt();
				}
				return arr;
			}
		}

		public long[] nextLongArray(int n, int f) {
			if (f == 0) {
				long[] arr = new long[n];
				for (int i = 0; i < n; i++) {
					arr[i] = nextLong();
				}
				return arr;
			} else {
				long[] arr = new long[n + 1];
				for (int i = 1; i < n + 1; i++) {
					arr[i] = nextLong();
				}
				return arr;
			}

		}

		public double[] nextDoubleArray(int n, int f) {
			if (f == 0) {
				double[] arr = new double[n];
				for (int i = 0; i < n; i++) {
					arr[i] = nextDouble();
				}
				return arr;
			} else {
				double[] arr = new double[n + 1];
				for (int i = 1; i < n + 1; i++) {
					arr[i] = nextDouble();
				}
				return arr;
			}
		}

	}

	static class Pair implements Comparable<Pair> {
		int a, b;

		Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if (this.a != o.a)
				return Integer.compare(this.a, o.a);
			else
				return Integer.compare(this.b, o.b);
		}

		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair) o;
				return p.a == a && p.b == b;
			}
			return false;
		}

		public int hashCode() {
			return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
		}

	}

}