#include<stdio.h>
int main()
{
    int n,k,flag,count1,count2,num[100000],i,count;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
    }
    flag=0;
    count=0;
    count2=0;
    for (k=0;k<n;k++)
    {
        if (num[0]==25)
        {
            if (num[k]==25)
            {
                count+=1;
                continue;
            }
            else
            {
                if (num[k]==50)
                {
                    count2+=1;
                    count-=1;
                    count1=count;
                }
                else if (num[k]==100)
                {
                    if (count2>0)
                    {
                        count2-=1;
                        count-=1;
                        count1=count;
                    }
                    else{
                        count-=3;
                        count1=count;
                    }
                }
                if (count1<0)
                {
                    flag=1;
                    break;
                }
            }
        }
        else{
            flag=1;
            break;
        }
    }
    if (flag==1){
        printf("NO");
        return 0;
    }
    else if(flag==0){
        printf("YES");
    }
        return 0;
}


#include<stdio.h>
int main()
{
    int n,k,flag,count1,count2,num[100],i,count;
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
    }
    flag=0;
    count=0;
    count2=0;
    for (k=0;k<n;k++)
    {
        if (num[0]==25)
        {
            if (num[k]==25)
            {
                count+=1;
                continue;
            }
            else
            {
                if (num[k]==50)
                {
                    count2+=1;
                    count-=1;
                    count1=count;
                }
                else if (num[k]==100)
                {
                    if (count2>0)
                    {
                        count2-=1;
                        count-=1;
                        count1=count;
                    }
                    else{
                        count-=3;
                        count1=count;
                    }
                }
                if (count1<0)
                {
                    flag=1;
                    break;
                }
            }
        }
        else{
            flag=1;
            break;
        }
    }
    if (flag==1){
        printf("NO");
        return 0;
    }
    else if(flag==0){
        printf("YES");
        return 0;
    }

}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x[10000],i,n,z=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        if (x[0]!=25)
        {
            printf ("NO");
            return 0;
        }
        if (x[i]==25)
        {
            z++;
        }
        else if(x[i]==50)
        {
            z--;
        }
        else if (x[i]==100)
        {
            z-=2;
        }

    }
    if (z<0)
        {
            printf("NO");
        }
        else
        {
            printf("YES");
        }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int x,i,n,y,z=0,o=0;
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&x);
        if (x==25)
        {
            z++;
        }
        else if(x==50)
        {
            z--;
            o++;
        }
        else if (x==100)
        {
            if (o>=1)
            {
                o--;
                z--;
            }
            else
            {
                z-=3;
            }
        }
        if (z<0)
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,i,n,y,z=0;
    scanf("%d",&n);
    scanf("%d",&y);
    if (y>25)
    {
        printf("NO");
        return 0;
    }
    else
    {
        z++;
    }
    for(i=1;i<n;i++)
    {
        scanf("%d",&x);
        if (x==25)
        {
            z++;
        }
        else if(x==50)
        {
            z--;
        }
        else if (x==100)
        {
            z-=3;
        }
        if (z<0)
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,i,n,y,z=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&x);
        if (x==25)
        {
            z++;
        }
        else if(x==50)
        {
            z--;
        }
        else if (x==100)
        {
            z-=3;
        }
        if (z<0)
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}


#include<stdio.h>

int main(){
	int n,money,sum1=0,sum2=0,t,temp;

	scanf("%d", &n);

	while(n--){
		scanf("%d", &money);
		if(money == 25)
			sum1 ++;
		if(money == 50){
			sum2 ++;
			sum1 --;
		}
		if(money == 75){
			if(sum2){
				sum2 --;
			}
			else{
				sum1 -= 2;
			}
		}
		if(money == 100){
			if(sum2){
				sum2 --;
				sum1 --;
			}
			else{
				sum1 -= 3;
			}
		}
		if(sum1 < 0 || sum2 < 0){
			printf("NO");
			return 0;
		}
	}

	printf("YES");
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
int main()
{
	int n,bucket[1000]={0};
	scanf("%d",&n);
	int a[n],i;
	for(i=0;i<n;i+=1)
	{
		scanf("%d",&a[i]);
		if(a[i]==25)
		{
			bucket[25]++;
		}
		if(a[i]==50)
		{
			if(bucket[25]==0)
			{
				printf("NO");
				return 0;
			}
			else
			{
				bucket[50]++;
				bucket[25]--;
			}
		}
		if(a[i]==100)
		{
			if(bucket[25]<1)
			{
				printf("NO");
				return 0;
			}
			if(bucket[50]<1 && bucket[25]<3)
			{
				printf("NO");
				return 0;
			}

		}
	}
	printf("YES");
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
int main()
{
	int n,bucket[1000]={0};
	scanf("%d",&n);
	int a[n],i;
	for(i=0;i<n;i+=1)
	{
		scanf("%d",&a[i]);
		if(a[i]==25)
		{
			bucket[25]++;
		}
		if(a[i]==50)
		{
			if(bucket[25]<=0)
			{
				printf("NO");
				return 0;
			}
			else
			{
				bucket[25]--;
			}
			bucket[50]++;
		}
		if(a[i]==100)
		{
			if(bucket[25]<1)
			{
				printf("NO");
				return 0;
			}
			if(bucket[50]<1 && bucket[25]<3)
			{
				printf("NO");
				return 0;
			}
			bucket[100]++;

		}
	}
	printf("YES");
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
int main()
{
	int n,bucket[1000]={0};
	scanf("%d",&n);
	int a,i;
	for(i=0;i<n;i+=1)
	{
		scanf("%d",&a);
		if(a==25)
		{
			bucket[25]++;
		}
		if(a==50)
		{
				bucket[25]--;
				bucket[50]++;
		}
		if(a==100)
		{
			bucket[100]++;
			bucket[25]--;
			if(bucket[50])
			{
				bucket[50]--;
			}
			else
			{
				bucket[25]--;
			}

		}
		if(bucket[25]<0 || bucket[50]<0)
		{
			printf("NO");
			return 0;
		}

	}
	printf("YES");
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e5 * 10;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

vector<ll> vec;
vector<vector<pair<ll, ll>>> graph;
bool used[SIZE];

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<ll> ans;
ll ups[SIZE][22], pr[SIZE][22], a[SIZE];

void dfs(int v) {
    used[v] = 1;

    for (int i = 0; i < 20; i++) {
        ups[v][i + 1] = ups[ups[v][i]][i];
        pr[v][i + 1] = pr[v][i] + pr[ups[v][i]][i];
    }

    for (auto to : graph[v]) {
        if (!used[to.first]) {
            ups[to.first][0] = v;
            pr[to.first][0] = to.second;
            dfs(to.first);
        }
    }
}

void add(int v) {
    ll cur = ups[v][0], lft = vec[v] - pr[v][0];
    if (lft < 0) return;
    a[cur]++;
    for (int i = 20; i >= 0; i--) {
        if (pr[cur][i] <= lft) {
            lft -= pr[cur][i];
            cur = ups[cur][i];
        }
    }

    if (cur != 0) {
        a[ups[cur][0]]--;
    }
}

ll cnt(int v) {
    ll cur = a[v];
    for (auto to : graph[v]) {
        cur += cnt(to.first);
    }
    ans[v] = cur;

    return cur;
}

int main() {
    fastInp;

    ll n, m;
    cin >> n;
    vec.resize(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

    graph.resize(n);
    ans.resize(n);

    for (int i = 0; i < n - 1; i++) {
        ll u, v;
        cin >> u >> v;
        u--;
        graph[u].push_back({ i + 1, v });
    }

    dfs(0);
    for (int i = 1; i < n; i++) add(i);
    cnt(0);
    for (int i = 0; i < n; i++) cout << ans[i] << " ";
    return 0;
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<memory.h>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

const int INF = 2000000000;
const double PI = acos(-1.0);

vector<int> wn;
vector< vector<pair<int, int> > > g;
vector<int> ans;

vector<pair<int, int> > path;
vector<int> part_sum;

void dfs(int v, int depth, int p = -1) {
    // cout << "CHECK\n";
    int L = 0, R = (int)path.size() - 1;
    int target = depth - wn[v];
    while(L < R) {
        int m = (L+R)/2;
        if (path[m].Y < target)
            L = m + 1;
        else
            R = m;
    }
    while(R >= 0 && path[R].Y >= target) R--;
    if (R >= 0)
        part_sum[path[R].X] --;
    if (path.size())
        part_sum[path.back().X] ++;
    // cout << "CHECK\n";
    path.push_back({v, depth});
    for (int i = 0; i < g[v].size(); i++) {
        dfs(g[v][i].X, depth + g[v][i].Y, v);
    }
    path.pop_back();
}

int go(int v) {
    int res = part_sum[v];
    for (int i = 0; i < g[v].size(); i++) {
        res += go(g[v][i].X);
    }
    ans[v] = res;
    return res;
}

int main() {
    int n;
    cin >> n;
    ans.resize(n);
    wn.resize(n);
    g.resize(n);
    part_sum.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> wn[i];
    }
    for (int i = 1; i < n; i++) {
        int p, _w;
        cin >> p >> _w;
        p --;
        g[p].push_back({i, _w});
    }

    dfs(0, 0);
    go(0);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<memory.h>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

const int INF = 2000000000;
const double PI = acos(-1.0);

vector<int> wn;
vector< vector<pair<int, int> > > g;
vector<int> ans;

vector<int> dfs(int v) {
    vector<int> res;
    for (int i = 0; i < g[v].size(); i++) {
        auto r = dfs(g[v][i].X);
        for(auto e: r) {
            int d = e - g[v][i].Y;
            if (d >= 0) {
                ans[v] ++;
                res.push_back(d);
            }
        }
    }
    // cout << v << ":";
    // for (int i = 0; i < res.size(); i++) {
    //     cout << res[i];
    // }
    // cout << endl;
    res.push_back(wn[v]);
    return res;
}

int main() {
    int n;
    cin >> n;
    ans.resize(n);
    wn.resize(n);
    g.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> wn[i];
    }
    for (int i = 1; i < n; i++) {
        int p, _w;
        cin >> p >> _w;
        p --;
        g[p].push_back({i, _w});
    }
    dfs(0);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}


//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
//#pragma comment(linker,"/STACK:33554432") /*32Mb*/
#define _CRT_SECURE_NO_DEPRECATE
#include<sstream>
#include<iostream>
#include<numeric>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<memory>
#include<memory.h>
#include<string>
#include<vector>
#include<cctype>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<complex>
#include<set>
#include<algorithm>

using namespace std;

typedef unsigned long long      ui64;
typedef long long               i64;
typedef	vector<int>             VI;
typedef	vector<bool>            VB;
typedef	vector<VI>              VVI;
typedef	vector<string>          VS;
typedef	pair<int,int>           PII;
typedef map<string,int>         MSI;
typedef set<int>                SI;
typedef set<string>             SS;
typedef complex<double>         CD;
typedef vector< CD >            VCD;
typedef map<int,int>            MII;
typedef	pair<double,double>     PDD;

#define PB                      push_back
#define MP                      make_pair
#define X                       first
#define Y                       second
#define FOR(i, a, b)            for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)           for(int i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b)             memset(a, b, sizeof(a))
#define SZ(a)                   int((a).size())
#define ALL(a)                  (a).begin(), (a).end()
#define RALL(a)                 (a).rbegin(), (a).rend()

#ifdef _DEBUG
#define eprintf(...) fprintf (stderr, __VA_ARGS__)
#else
#define eprintf(...) assert (true)
#endif

const int INF = 2000000000;
const double PI = acos(-1.0);

vector<long long> wn;
vector< vector<pair<int, long long> > > g;
vector<long long> ans;

vector<pair<int, long long> > path;
vector<long long> part_sum;

void dfs(int v, long long depth, int p = -1) {
    // cout << "CHECK\n";
    int L = 0, R = (int)path.size() - 1;
    long long target = depth - wn[v];
    while(L < R) {
        int m = (L+R)/2;
        if (path[m].Y < target)
            L = m + 1;
        else
            R = m;
    }
    while(R >= 0 && path[R].Y >= target) R--;
    if (R >= 0)
        part_sum[path[R].X] --;
    if (path.size())
        part_sum[path.back().X] ++;
    // cout << "CHECK\n";
    path.push_back({v, depth});
    for (int i = 0; i < g[v].size(); i++) {
        dfs(g[v][i].X, depth + g[v][i].Y, v);
    }
    path.pop_back();
}

long long go(int v) {
    long long res = part_sum[v];
    for (int i = 0; i < g[v].size(); i++) {
        res += go(g[v][i].X);
    }
    ans[v] = res;
    return res;
}

int main() {
    int n;
    cin >> n;
    ans.resize(n);
    wn.resize(n);
    g.resize(n);
    part_sum.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> wn[i];
    }
    for (int i = 1; i < n; i++) {
        int p, _w;
        cin >> p >> _w;
        p --;
        g[p].push_back({i, _w});
    }

    dfs(0, 0);
    go(0);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " ";
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll int
#define N 200005
using namespace std;
ll res[N],a[N],n,u,v;
vector<pair<ll,ll>>g[N],ans[N];
void dfs(ll node)
{
    if(g[node].size()==0)
    {
        res[node]=0;
        ans[node].push_back({
            0,a[node]
        });
        return;
    }
    for(auto child:g[node])
    {
        dfs(child.first);
        for(auto x:ans[child.first])
        {
            if((child.second+x.first)<=x.second)
            ans[node].push_back({
                child.second+x.first,x.second
            });
        }
    }
    res[node]=ans[node].size();
    ans[node].push_back({
        0,a[node]
    });
}
int main()
{
    scanf("%d",&n);
    for(ll i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(ll i=2;i<=n;i++)
    {
        scanf("%d%d",&u,&v);
        g[u].push_back({
            i,v
        });
    }
    dfs(1);
    for(ll i=1;i<=n;i++)
    printf("%d ",res[i]);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
vector<pair<int,ll>>g[N];
vector<pair<ll,int>>sumdist;
int n,ans[N],p[N];
ll a[N],w[N];
void dfs(int node,ll dist)
{
    sumdist.push_back({
        dist,node
    });
    int t=lower_bound(sumdist.begin(),sumdist.end(),make_pair((dist-a[node]),0))->second;
    ans[p[t]]--;
    ans[p[node]]++;
    for(auto v:g[node])
    {
        dfs(v.first,dist+v.second);
        ans[node]+=ans[v.first];
    }
    sumdist.pop_back();
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    scanf("%lld",&a[i]);
    for(int i=2;i<=n;i++)
    {
        scanf("%d%lld",&p[i],&w[i]);
        g[p[i]].push_back({
            i,w[i]
        });
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
    printf("%d ",ans[i]);
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 200005
using namespace std;
ll res[N],a[N],n,u,v;
vector<pair<ll,ll>>g[N],ans[N];
void dfs(ll node)
{
    if(g[node].size()==0)
    {
        res[node]=0;
        ans[node].push_back({
            0,a[node]
        });
        return;
    }
    for(auto child:g[node])
    {
        dfs(child.first);
        for(auto x:ans[child.first])
        {
            if((child.second+x.first)<=x.second)
            ans[node].push_back({
                child.second+x.first,x.second
            });
        }
    }
    res[node]=ans[node].size();
    ans[node].push_back({
        0,a[node]
    });
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++)
    scanf("%lld",&a[i]);
    for(ll i=2;i<=n;i++)
    {
        scanf("%lld%lld",&u,&v);
        g[u].push_back({
            i,v
        });
    }
    dfs(1);
    for(ll i=1;i<=n;i++)
    printf("%d ",res[i]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5+20;
int a[Maxn],ans[Maxn];
int p[Maxn],w[Maxn];
vector<pair<long long,int> >  dis;
vector<int> d[Maxn];
void dfs(int u,long long dist){
    dis.push_back(make_pair(dist,u));
    int t = lower_bound(dis.begin(),dis.end(),make_pair(dist - a[u]-1,0))->second;
    ans[t] --;
    ans[p[u]] ++;
    for(int v:d[u]){
        dfs(v,dist+w[v]);
        ans[u] += ans[v];
    }
    dis.pop_back();
}
main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i];
    for(int i=2;i<=n;i++){
        cin >> p[i] >> w[i];
        d[p[i]].push_back(i);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        cout << ans[i] <<" ";

}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e5;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int a[maxn];
int ps[maxn];
vector < pii > adj[maxn];
int par[maxn][20];
int dist[maxn];

void dfs(int v = 1,  int d = 0){
    dist[v] = d;
    for(auto [u , w] : adj[v])
        dfs(u , d + w);
}

void solve(int v = 1){
    for(auto [u , w] : adj[v])
        solve(u);
    for(auto [u , w] : adj[v])
        ps[v] += ps[u];
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> a[i];
    for(int i = 2 ; i <= n ; i ++){
        int p , w;
        cin >> p >> w;
        adj[p].pb({i , w});
        par[i][0] = p;
    }
    dfs();
    for(int i = 1 ; i < 20 ; i ++)
        for(int j = 1 ; j <= n ; j ++)
            par[j][i] = par[par[j][i-1]][i-1];
    for(int i = 1 ; i <= n ; i ++){
        ps[i] ++;
        int pos = i;
        for(int j = 19 ; j >= 0 ; j --){
            if(!par[pos][j])continue;
            if(a[i] < dist[i] - dist[par[pos][j]])continue;
            pos = par[pos][j];
        }
        ps[par[pos][0]] --;
    }
    solve();
    for(int i = 1 ; i <= n ; i ++)
        cout << ps[i]-1 << ' ';
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e5;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int a[maxn];
int ps[maxn];
vector < pii > adj[maxn];
int par[maxn][20];
int dist[maxn];

void dfs(int v = 1,  int d = 0){
    dist[v] = d;
    for(auto [u , w] : adj[v])
        dfs(u , d + w);
}

void solve(int v = 1){
    for(auto [u , w] : adj[v])
        solve(u);
    for(auto [u , w] : adj[v])
        ps[v] += ps[u];
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> a[i];
    for(int i = 2 ; i <= n ; i ++){
        int p , w;
        cin >> p >> w;
        adj[p].pb({i , w});
        par[i][0] = p;
    }
    dfs();
    for(int i = 1 ; i < 20 ; i ++)
        for(int j = 1 ; j <= n ; j ++)
            par[i][j] = par[par[i][j-1]][j-1];
    for(int i = 1 ; i <= n ; i ++){
        ps[i] ++;
        int pos = i;
        for(int j = 19 ; j >= 0 ; j --){
            if(!par[pos][j])continue;
            if(a[i] < dist[i] - dist[par[pos][j]])continue;
            pos = par[pos][j];
        }
        ps[par[pos][0]] --;
    }
    solve();
    for(int i = 1 ; i <= n ; i ++)
        cout << ps[i]-1 << ' ';
    return(0);
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const int N = 2e5 + 1;
vector<pair<int, int>> g[N];
int col[N];
unordered_map<int, pair<int, int>> m[N];
int ans[N];

void fun(int u = 1, int p = 0) {
	for (auto j : g[u]) {
		if (j.first == p)continue;
		fun(j.first, u);
		for (auto i : m[j.first]) {
			if (i.second.second + j.second <= i.second.first)
				m[u][i.first] = {i.second.first, i.second.second + j.second};
		}
		m[j.first].clear();
	}
	m[u][u] = {col[u], 0};
	ans[u] = m[u].size() - 1;
}

int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)cin >> col[i];
		for (int i = 1; i < n; i++) {
			int a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		fun();
		for (int i = 1; i <= n; i++) {
			cout << ans[i] << " ";
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const ll N = 2e5 + 1;
vector<pair<ll, ll>> g[N];
ll col[N];
ll par[N][25];
ll sc[N][25];
ll h[N];
ll ans[N];
ll n;
ll s[N];
ll ret[N];

void dfs(ll u = 1, ll p = 0, ll val = 0) {
	par[u][0] = p;
	h[u] = h[p] + 1;
	sc[u][0] = val;
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs(i.first, u, i.second);
		s[u] += 1;
	}
}

void pre() {
	for (ll i = 1; i <= 24; i++) {
		for (ll j = 1; j <= n; j++) {
			if (par[j][i - 1]) {
				par[j][i] = par[par[j][i - 1]][i - 1];
				sc[j][i] += sc[par[j][i - 1]][i - 1];
				sc[j][i] += sc[j][i - 1];
			}
		}
	}
}

void dfs2(ll u = 1, ll p = 0) {
	ret[u] = s[u] + ans[u];
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs2(i.first, u);
		ret[u] += ret[i.first];
	}
}

void lift(ll a) {
	ll u = a;
	ll val = 0;
	for (ll i = 24; i >= 0; i--) {
		if (par[a][i] && (sc[a][i] + val) <= col[u])val += sc[a][i], a = par[a][i];
	}
	ans[par[a][0]] += -1;
}

int main() {
	Fast;
	ll t = 1;
	judge();
	// cin >> t;
	while (t--) {
		cin >> n;
		for (ll i = 1; i <= n; i++)cin >> col[i];
		for (ll i = 1; i < n; i++) {
			ll a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		dfs();
		pre();
		for (ll i = 1; i <= n; i++) {
			lift(i);
		}
		dfs2();
		for (ll i = 1; i <= n; i++) {
			cout << ret[i] << " ";
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const int N = 2e5 + 1;
vector<pair<int, int>> g[N];
int col[N];
int par[N][25];
int sc[N][25];
int h[N];
int ans[N];
int n;
int s[N];
int ret[N];

void dfs(int u = 1, int p = 0, int val = 0) {
	par[u][0] = p;
	h[u] = h[p] + 1;
	sc[u][0] = val;
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs(i.first, u, i.second);
		s[u] += 1;
	}
}

void pre() {
	for (int i = 1; i <= 24; i++) {
		for (int j = 1; j <= n; j++) {
			if (par[j][i - 1]) {
				par[j][i] = par[par[j][i - 1]][i - 1];
				sc[j][i] += sc[par[j][i - 1]][i - 1];
				sc[j][i] += sc[j][i - 1];
			}
		}
	}
}

void dfs2(int u = 1, int p = 0) {
	ret[u] = s[u] + ans[u];
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs2(i.first, u);
		ret[u] += ret[i.first];
	}
}

void lift(int a) {
	// ans[a] += 1;
	int u = a;
	int val = 0;
	for (int i = 24; i >= 0; i--) {
		if (par[a][i] && (sc[a][i] + val) <= col[a])a = par[a][i], val += sc[a][i];
	}
	// cout << u << " " << a << endl;
	// if (!val)return;
	ans[par[a][0]] += -1;
}

void dfs1(int u = 1, int p = 0) {
	for (auto i : g[u]) {
		if (i.first == p)continue;
		ans[i.first] += ans[u];
		dfs1(i.first, u);
		// ans[u] += ans[i.first];
	}
}

int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++)cin >> col[i];
		for (int i = 1; i < n; i++) {
			int a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		dfs();
		pre();
		// for (int i = 1; i <= n; i++) {
		// 	for (int j = 0; j <= 1; j++) {
		// 		cout << i << " " << j << " " << par[i][j] << " " << sc[i][j] << endl;
		// 	}
		// }
		for (int i = 1; i <= n; i++) {
			lift(i);
		}
		// for (int i = 0; i <= n; i++) {
		// 	cout << i << " " << ans[i] << endl;
		// }
		dfs2();
		for (int i = 1; i <= n; i++) {
			cout << ret[i] << " ";
		}
		// for (int i = 1; i <= n; i++) {
		// 	cout << ans[i] - 1 << " ";
		// }
		// for (int i = 1; i <= n; i++) {
		// 	cout << abs(ans[par[i][0]]) << " ";
		// }
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const ll N = 2e5 + 1;
vector<pair<ll, ll>> g[N];
ll col[N];
ll par[N][25];
ll sc[N][25];
ll h[N];
ll ans[N];
ll n;
ll s[N];
ll ret[N];

void dfs(ll u = 1, ll p = 0, ll val = 0) {
	par[u][0] = p;
	h[u] = h[p] + 1;
	sc[u][0] = val;
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs(i.first, u, i.second);
		s[u] += 1;
	}
}

void pre() {
	for (ll i = 1; i <= 24; i++) {
		for (ll j = 1; j <= n; j++) {
			if (par[j][i - 1]) {
				par[j][i] = par[par[j][i - 1]][i - 1];
				sc[j][i] += sc[par[j][i - 1]][i - 1];
				sc[j][i] += sc[j][i - 1];
			}
		}
	}
}

void dfs2(ll u = 1, ll p = 0) {
	ret[u] = s[u] + ans[u];
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs2(i.first, u);
		ret[u] += ret[i.first];
	}
}

void lift(ll a) {
	// ans[a] += 1;
	ll u = a;
	ll val = 0;
	for (ll i = 24; i >= 0; i--) {
		if (par[a][i] && (sc[a][i] + val) <= col[u])val += sc[a][i], a = par[a][i];
	}
	// cout << u << " " << a << " " << val << endl;
	// if (!val)return;
	ans[par[a][0]] += -1;
}

void dfs1(ll u = 1, ll p = 0) {
	for (auto i : g[u]) {
		if (i.first == p)continue;
		ans[i.first] += ans[u];
		dfs1(i.first, u);
		// ans[u] += ans[i.first];
	}
}

int main() {
	Fast;
	ll t = 1;
	judge();
	// cin >> t;
	while (t--) {
		cin >> n;
		for (ll i = 1; i <= n; i++)cin >> col[i];
		for (ll i = 1; i < n; i++) {
			ll a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		dfs();
		pre();
		// for (ll i = 1; i <= n; i++) {
		// 	for (ll j = 0; j <= 2; j++) {
		// 		cout << i << " " << j << " " << par[i][j] << " " << sc[i][j] << endl;
		// 	}
		// }
		for (ll i = 1; i <= n; i++) {
			lift(i);
		}
		// for (ll i = 0; i <= n; i++) {
		// 	cout << i << " " << ans[i] << endl;
		// }
		dfs2();
		for (ll i = 1; i <= n; i++) {
			cout << ret[i] << " ";
		}
		// for (ll i = 1; i <= n; i++) {
		// 	cout << ans[i] - 1 << " ";
		// }
		// for (ll i = 1; i <= n; i++) {
		// 	cout << abs(ans[par[i][0]]) << " ";
		// }
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const int N = 2e5 + 1;
vector<pair<int, int>> g[N];
int col[N];
int par[N][25];
int sc[N][25];
int h[N];
int ans[N];
int n;
int s[N];
int ret[N];

void dfs(int u = 1, int p = 0, int val = 0) {
	par[u][0] = p;
	h[u] = h[p] + 1;
	sc[u][0] = val;
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs(i.first, u, i.second);
		s[u] += 1;
	}
}

void pre() {
	for (int i = 1; i <= 24; i++) {
		for (int j = 1; j <= n; j++) {
			if (par[j][i - 1]) {
				par[j][i] = par[par[j][i - 1]][i - 1];
				sc[j][i] += sc[par[j][i - 1]][i - 1];
				sc[j][i] += sc[j][i - 1];
			}
		}
	}
}

void dfs2(int u = 1, int p = 0) {
	ret[u] = s[u] + ans[u];
	for (auto i : g[u]) {
		if (i.first == p)continue;
		dfs2(i.first, u);
		ret[u] += ret[i.first];
	}
}

void lift(int a) {
	// ans[a] += 1;
	int u = a;
	int val = 0;
	for (int i = 24; i >= 0; i--) {
		if (par[a][i] && (sc[a][i] + val) <= col[u])val += sc[a][i], a = par[a][i];
	}
	// cout << u << " " << a << " " << val << endl;
	// if (!val)return;
	ans[par[a][0]] += -1;
}

void dfs1(int u = 1, int p = 0) {
	for (auto i : g[u]) {
		if (i.first == p)continue;
		ans[i.first] += ans[u];
		dfs1(i.first, u);
		// ans[u] += ans[i.first];
	}
}

int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; i++)cin >> col[i];
		for (int i = 1; i < n; i++) {
			int a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		dfs();
		pre();
		// for (int i = 1; i <= n; i++) {
		// 	for (int j = 0; j <= 2; j++) {
		// 		cout << i << " " << j << " " << par[i][j] << " " << sc[i][j] << endl;
		// 	}
		// }
		for (int i = 1; i <= n; i++) {
			lift(i);
		}
		// for (int i = 0; i <= n; i++) {
		// 	cout << i << " " << ans[i] << endl;
		// }
		dfs2();
		for (int i = 1; i <= n; i++) {
			cout << ret[i] << " ";
		}
		// for (int i = 1; i <= n; i++) {
		// 	cout << ans[i] - 1 << " ";
		// }
		// for (int i = 1; i <= n; i++) {
		// 	cout << abs(ans[par[i][0]]) << " ";
		// }
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const int N = 2e5 + 1;
vector<pair<int, int>> g[N];
int col[N];
unordered_map<int, pair<int, int>> m[N];

void fun(int u = 1, int p = 0) {
	for (auto j : g[u]) {
		if (j.first == p)continue;
		fun(j.first, u);
		for (auto i : m[j.first]) {
			if (i.second.second + j.second <= i.second.first)
				m[u][i.first] = {i.second.first, i.second.second + j.second};
		}
	}
	m[u][u] = {col[u], 0};
}

int main() {
	Fast;
	int t = 1;
	judge();
	// cin >> t;
	while (t--) {
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)cin >> col[i];
		for (int i = 1; i < n; i++) {
			int a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		fun();
		for (int i = 1; i <= n; i++) {
			cout << m[i].size() - 1 << " ";
		}
	}
}


#include <bits/stdc++.h>
#define ll long long
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define Fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;

void judge() {
#ifndef ONLINE_JUDGE
	FILE_READ_IN
	FILE_READ_OUT
#endif
}
const ll N = 2e5 + 1;
priority_queue<ll> q[N];
vector<pair<ll, ll>> g[N];
ll pt[N];
ll col[N];
int ans[N];
int n;

void dfs(ll u = 1, ll p = 0, ll dis = 0) {
	pt[u] = u;
	for (auto i : g[u]) {
		ll v = i.first;
		if (i.first == p)continue;
		dfs(i.first, u, dis + i.second);
		if (q[pt[u]].size() < q[pt[v]].size()) {
			while (!q[pt[u]].empty())q[pt[v]].push(q[pt[u]].top()), q[pt[u]].pop();
			pt[u] = pt[v];
		}
		else
			while (!q[pt[v]].empty())q[pt[u]].push(q[pt[v]].top()), q[pt[v]].pop();
	}
	while (!q[pt[u]].empty() && q[pt[u]].top() > dis )q[pt[u]].pop();
	ans[u] = q[pt[u]].size();
	q[pt[u]].push(dis - col[u]);
}

int main() {
	Fast;
	ll t = 1;
	judge();
	// cin >> t;
	while (t--) {
		cin >> n;
		for (ll i = 1; i <= n; i++)cin >> col[i];
		for (ll i = 1; i < n; i++) {
			ll a, b;
			cin >> a >> b;
			g[i + 1].push_back({a, b});
			g[a].push_back({i + 1, b});
		}
		dfs();
		for (ll i = 1; i <= n; i++) {
			cout << ans[i] << " ";
		}
	}
}


#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[N],res[N],dist[N];
map<pll,ll>map1;
//<<-----Implement Functions Here---->>//
ll l;
vector<vector<ll>> up;
void dfs(ll v,ll p = 0,ll dis = 0)
{
    up[v][0] = p;dist[v] = dis;
    for (ll i = 1; i <= l; ++i)
       	up[v][i] = up[up[v][i-1]][i-1];

    for (ll u:adj[v]){
        if(u==p)continue;
        dfs(u, v,dis+map1[{u,v}]);
    }
}
ll getparent(ll u)
{
	ll v = u;
	for(ll i = l;i >= 0;i--)
	{
		if(dist[u]-dist[up[u][i]]<=a[v]){
			u = up[u][i];
		}
	}
	return up[u][0];
}
void last(ll x,ll p)
{
    ll h = 0;
    for(auto it:adj[x])
    {
        if(it==p)continue;
        last(it,x);h += res[it];
    }
    res[x] += h;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;
		for(ll i=1;i<=n;i++)cin>>a[i];

		for(ll i=2;i<=n;i++)
		{
			ll p,w;cin>>p>>w;
			adj[i].pb(p);adj[p].pb(i);
			map1[{p,i}] = w;map1[{i,p}] = w;
		}

		l = ceil(log2(n));
 		up.assign(n+3, vector<ll>(l + 1));
 		dfs(1);

 		for(ll i=1;i<=n;i++)
 		{
 			ll u = up[i][0];
 			ll v = getparent(i);
 			res[u] += 1;
 			res[v] -= 1;
 			//cout<<u<<" "<<v<<endl;
 		}

 		last(1,0);
 		for(ll i=1;i<=n;i++)cout<<res[i]<<" ";

}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}


#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vpll adj[N];
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[N],res[N],dist[N];
map<pll,ll>map1;
//<<-----Implement Functions Here---->>//
ll l;
vector<vector<ll>> up;
void dfs(ll v,ll p = 0,ll dis = 0)
{
    up[v][0] = p;dist[v] = dis;
    for (ll i = 1; i <= l; i++)
       	up[v][i] = up[up[v][i-1]][i-1];

    for (auto [u,w]:adj[v]){
        if(u==p)continue;
        dfs(u, v,dis+w);
    }
}
ll getparent(ll u)
{
	ll v = u;
	for(ll i = l;i >= 0;i--)
	{
		if(dist[u]-dist[up[v][i]]<=a[u]){
			v = up[v][i];
		}
	}
	return up[v][0];
}
void last(ll x,ll p)
{
    ll h = 0;
    for(auto [it,w]:adj[x])
    {
        if(it==p)continue;
        last(it,x);h += res[it];
    }
    res[x] += h;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;
		for(ll i=1;i<=n;i++)cin>>a[i];

		for(ll i=2;i<=n;i++)
		{
			ll p,w;cin>>p>>w;
			adj[i].pb({p,w});adj[p].pb({i,w});

		}
		l = ceil(log2(n));
 		up.assign(n+3, vector<ll>(l + 1));
 		dfs(1);

 		for(ll i=1;i<=n;i++)
 		{
 			ll u = up[i][0];
 			ll v = getparent(i);
 			res[u] += 1;
 			res[v] -= 1;
 			//cout<<u<<" "<<v<<endl;
 		}

 		last(1,0);
 		for(ll i=1;i<=n;i++)cout<<res[i]<<" ";

}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}


#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,a[N],res[N],dist[N];
map<pll,ll>map1;
//<<-----Implement Functions Here---->>//
ll l;
vector<vector<ll>> up;
void dfs(ll v,ll p = 0,ll dis = 0)
{
    up[v][0] = p;dist[v] = dis;
    for (ll i = 1; i <= l; ++i)
       	up[v][i] = up[up[v][i-1]][i-1];

    for (ll u:adj[v]){
        if(u==p)continue;
        dfs(u, v,dis+map1[{u,v}]);
    }
}
ll getparent(ll u)
{
	for(ll i = l;i >= 0;i--)
	{
		if(dist[u]-dist[up[u][i]]<=a[u]){
			u = up[u][i];
		}
	}
	return up[u][0];
}
void last(ll x,ll p)
{
    ll h = 0;
    for(auto it:adj[x])
    {
        if(it==p)continue;
        last(it,x);h += res[it];
    }
    res[x] += h;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n;
		for(ll i=1;i<=n;i++)cin>>a[i];

		for(ll i=2;i<=n;i++)
		{
			ll p,w;cin>>p>>w;
			adj[i].pb(p);adj[p].pb(i);
			map1[{p,i}] = w;map1[{i,p}] = w;
		}

		l = ceil(log2(n));
 		up.assign(n+3, vector<ll>(l + 1));
 		dfs(1);

 		for(ll i=1;i<=n;i++)
 		{
 			ll u = up[i][0];
 			ll v = getparent(i);
 			res[u] += 1;
 			res[v] -= 1;

 		}

 		last(1,0);
 		for(ll i=1;i<=n;i++)cout<<res[i]<<" ";

}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}


#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>
#define deb(x)		cout << #x << " " << x << endl

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 2e5 + 10;
vpii adj[N];
vi dis(N , 0) , ord , in(N , 0) , out(N , 0) , val(N , 0) , tree[N];
int timer = -1;

void dfs(int src, int par){
    //cout << "src " << src << " " << dis[src] << " " << val[src]<< '\n';
    val[src] = dis[src] - val[src];
    timer++;
    in[src] = timer;
    ord.eb(val[src]);
    for(auto e : adj[src]){
        if(e.f == par) continue;
        dis[e.f] = e.s + dis[src];
        //val[e.f] += (e.s + dis[e.f]);
        dfs(e.f , src);
    }
    out[src] = timer;
}

void build(int l , int r , int t){
    if(l == r){
        tree[t].eb(ord[l]);
        return ;
    }
    int mid = (l + r) >> 1;
    build(l , mid , t << 1);
    build(mid + 1 , r , t << 1 | 1);
    merge(all(tree[t << 1]) , all(tree[t << 1 | 1]) , back_inserter(tree[t]));
}

int qry(int l , int r , int t , int ql , int qr , int x){
    if(l > qr || r < ql)
        return 0;
    if(l >= ql && r <= qr){
        int y = upper_bound(all(tree[t]) , x) - tree[t].begin();
        //y -> number of elements in the range which are less than equal to x
        return y;
    }
    int mid = (l + r) >> 1;
    return qry(l , mid , t << 1 , ql , qr , x) + qry(mid + 1 , r , t << 1 | 1 , ql , qr , x);
}

signed main(){

#ifndef ONLINE_JUDGE
//	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    cin >> n;
    fo(i , n) cin >> val[i];
    fo(i , n-1){
        int p , w;
        cin >> p >> w;
        p--;
        adj[i + 1].eb(p , w);
        adj[p].eb(i + 1 , w);
    }

    dfs(0 , -1);
    build(0 , n - 1 , 1);

    fo(i , n){
        cout << qry(0 , n - 1 , 1 , in[i] + 1 , out[i] , dis[i]) << ' ';
    }
    return 0;

}


#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>
#define deb(x)		cout << #x << " " << x << endl

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 2e5 + 10;
vpii adj[N];
vi dis(N , 0) , ord , in(N , 0) , out(N , 0) , val(N , 0) , tree[N << 2];
int timer = -1;

void dfs(int src, int par){
    //cout << "src " << src << " " << dis[src] << " " << val[src]<< '\n';
    val[src] = dis[src] - val[src];
    timer++;
    in[src] = timer;
    ord.eb(val[src]);
    for(auto e : adj[src]){
        if(e.f == par) continue;
        dis[e.f] = e.s + dis[src];
        //val[e.f] += (e.s + dis[e.f]);
        dfs(e.f , src);
    }
    out[src] = timer;
}

void build(int l , int r , int t){
    if(l == r){
        tree[t].eb(ord[l]);
        return ;
    }
    int mid = (l + r) >> 1;
    build(l , mid , t << 1);
    build(mid + 1 , r , t << 1 | 1);
    merge(all(tree[t << 1]) , all(tree[t << 1 | 1]) , back_inserter(tree[t]));
}

int qry(int l , int r , int t , int ql , int qr , int x){
    if(l > qr || r < ql)
        return 0;
    if(l >= ql && r <= qr){
        int y = upper_bound(all(tree[t]) , x) - tree[t].begin();
        //y -> number of elements in the range which are less than equal to x
        return y;
    }
    int mid = (l + r) >> 1;
    return qry(l , mid , t << 1 , ql , qr , x) + qry(mid + 1 , r , t << 1 | 1 , ql , qr , x);
}

signed main(){

#ifndef ONLINE_JUDGE
//	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    cin >> n;
    fo(i , n) cin >> val[i];
    fo(i , n-1){
        int p , w;
        cin >> p >> w;
        p--;
        adj[i + 1].eb(p , w);
        adj[p].eb(i + 1 , w);
    }

    dfs(0 , -1);
    build(0 , n - 1 , 1);

    fo(i , n){
        cout << qry(0 , n - 1 , 1 , in[i] + 1 , out[i] , dis[i]) << ' ';
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll N=200200, H=30;
ll n, a[N], dep[N], par[N][H], f[N];
vector<pair<ll, ll>> adj[N];
void dfs(ll x, ll from) {
	par[x][0] = from;
	for (ll i= 1; i < H; ++i) {
		par[x][i] = par[par[x][i-1]][i-1];
		assert(par[x][i]);
	}
	f[x]++;
	ll y = x;
	for (int i = H-1; i >= 0; --i)
		if (dep[par[y][i]] >= dep[x] - a[x])
			y = par[y][i];
	y = par[y][0];
	if (dep[y] < dep[x]-a[x]) f[y]--;

	for (auto& e : adj[x]) {
		dep[e.first] = dep[x] + e.second;
		dfs(e.first, x);
		f[x] += f[e.first];
	}
}
int main() {
	cin >> n;
	for (ll i = 1; i <= n; ++i) cin >> a[i];
	for (ll i = 2; i <= n; ++i) {
		ll p, w;
		cin >> p >> w;
		adj[p].emplace_back(i, w);
	}
	dfs(1,1);
	for (ll i = 1; i <= n; ++i) cout << (f[i]-1) << " ";
}


#include <bits/stdc++.h>
#define N 100005

using namespace std;
typedef pair<int,int> ii;
vector<vector<ii>> AdjList(N);
int P[N][18];
int dist[N],res[N],a[N];

void DFS(int u,int p)
{
    for(int i=1;i<18;i++)
        P[u][i] = P[P[u][i-1]][i-1];
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            P[v.first][0] = u;
            dist[v.first] = dist[u] + v.second;
            DFS(v.first,u);
        }
    }
}

void solve(int u,int p)
{
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            solve(v.first,u);
            res[u] += res[v.first];
        }
    }

    // we will add 1 to the ancestor of u if dist[u] - a[u] <= dist[p]
    int limit = dist[u] - a[u];
    int start = u;
    for(int i=17;i>=0;i--)
    {
        if(limit <= dist[P[start][i]])
            start = P[start][i];
    }

    if(limit <= dist[P[u][0]])
    {
        res[P[u][0]] ++;
        res[P[start][0]] --; // nhung thang < start se ko thoa man
    }
}

signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        int p,w;
        cin>>p>>w;
        AdjList[p].push_back(ii(i,w));
    }

    //P[1][0] = 1;
    DFS(1,0);
    solve(1,0);

    for(int i=1;i<=n;i++)
        cout<<res[i]<<" ";

}


#include <bits/stdc++.h>
#define int long long
#define N 200005

using namespace std;
typedef pair<int,int> ii;
vector<vector<ii>> AdjList(N);
int P[N][18];
int dist[N],res[N],a[N];

void DFS(int u,int p)
{
    for(int i=1;i<18;i++)
        P[u][i] = P[P[u][i-1]][i-1];
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            P[v.first][0] = u;
            dist[v.first] = dist[u] + v.second;
            DFS(v.first,u);
        }
    }
}

void solve(int u,int p)
{
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            solve(v.first,u);
            res[u] += res[v.first];
        }
    }

    // we will add 1 to the ancestor of u if dist[u] - a[u] <= dist[p]
    int limit = dist[u] - a[u];
    int start = u;
    for(int i=17;i>=0;i--)
    {
        if(limit <= dist[P[start][i]])
            start = P[start][i];
    }

    if(limit <= dist[P[u][0]])
    {
        res[P[u][0]] ++;
        res[P[start][0]] --; // nhung thang < start se ko thoa man
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        int p,w;
        cin>>p>>w;
        AdjList[p].push_back(ii(i,w));
    }

    //P[1][0] = 1;
    DFS(1,0);
    solve(1,0);

    for(int i=1;i<=n;i++)
        cout<<res[i]<<" ";

}


#include <bits/stdc++.h>
#define N 200005

using namespace std;
typedef pair<int,int> ii;
vector<vector<ii>> AdjList(N);
int P[N][18];
int dist[N],res[N],a[N];

void DFS(int u,int p)
{
    for(int i=1;i<18;i++)
        P[u][i] = P[P[u][i-1]][i-1];
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            P[v.first][0] = u;
            dist[v.first] = dist[u] + v.second;
            DFS(v.first,u);
        }
    }
}

void solve(int u,int p)
{
    for(ii v:AdjList[u])
    {
        if(v.first != p)
        {
            solve(v.first,u);
            res[u] += res[v.first];
        }
    }

    // we will add 1 to the ancestor of u if dist[u] - a[u] <= dist[p]
    int limit = dist[u] - a[u];
    int start = u;
    for(int i=17;i>=0;i--)
    {
        if(limit <= dist[P[start][i]])
            start = P[start][i];
    }

    if(limit <= dist[P[u][0]])
    {
        res[P[u][0]] ++;
        res[P[start][0]] --; // nhung thang < start se ko thoa man
    }
}

signed main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        int p,w;
        cin>>p>>w;
        AdjList[p].push_back(ii(i,w));
    }

    //P[1][0] = 1;
    DFS(1,0);
    solve(1,0);

    for(int i=1;i<=n;i++)
        cout<<res[i]<<" ";

}


#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define PI 3.14159265
#define cbrt cbrtl
using namespace std;
map< pair<ll,ll> ,ll> mpp;
ll n;
vector<ll> adj[200005];
ll dep[200005],a[200005],ans[200005];
vector< pair<ll,ll> > dfs(ll u,ll p)
{
  dep[u]=dep[p];
  if(p!=0)
    dep[u]+=mpp[mp(p,u)];
  ll i;
  vector< pair<ll,ll> > temp;
  temp.clear();
  for(i=0;i<adj[u].size();i++)
  {
    ll x=adj[u][i];
    if(x!=p)
    {
      vector < pair<ll,ll> > t=dfs(x,u);
      temp.insert(temp.begin(),t.begin(),t.end());
    }
  }
  sort(all(temp));
  ll l=0,r=(ll)temp.size()-1,mid;
  ll val=-1;
  while(l<=r)
  {
    mid=(l+r)/2;
    if(temp[mid].ff<=dep[u])
    {
       val=mid;
       l=mid+1;
    }
    else
      r=mid-1;
  }
  ans[u]=val+1;
  temp.pb(mp(dep[u]-a[u],u));
  return temp;
}
int main()
{
  cin>>n;
  ll i;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(i=2;i<=n;i++)
  {
     ll u,w;
     cin>>u>>w;
     adj[i].pb(u);
     adj[u].pb(i);
     mpp[mp(i,u)]=w;
     mpp[mp(u,i)]=w;
  }
  dfs(1,0);
  for(i=1;i<=n;i++)
    cout<<ans[i]<<" ";
  return 0;
}


#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define PI 3.14159265
#define cbrt cbrtl
using namespace std;
map< pair<ll,ll> ,ll> mpp;
ll n;
vector<ll> adj[200005];
ll dep[200005],a[200005],ans[200005];
set< pair<ll,ll> > dfs(ll u,ll p)
{
  dep[u]=dep[p];
  if(p!=0)
    dep[u]+=mpp[mp(p,u)];
  ll i;
  set< pair<ll,ll> > temp;
  temp.clear();
  for(i=0;i<adj[u].size();i++)
  {
    ll x=adj[u][i];
    if(x!=p)
    {
      set < pair<ll,ll> > t=dfs(x,u);
      temp.insert(t.begin(),t.end());
    }
  }
 // cout<<u<<" "<<temp.size()<<" ";
  pair<ll,ll> t;
  t.ff=dep[u];
  t.ss=1e18;
  auto it=temp.upper_bound(t);
  if(it!=temp.end())
    temp.erase(it,temp.end());
  ans[u]=(ll)temp.size();
  //cout<<temp.size()<<" ";
  temp.insert(mp(dep[u]-a[u],u));
  //cout<<temp.size()<<"\n";
  //cout<<dep[u]-a[u]<<"\n";
  return temp;
}
int main()
{
  cin>>n;
  ll i;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(i=2;i<=n;i++)
  {
     ll u,w;
     cin>>u>>w;
     adj[i].pb(u);
     adj[u].pb(i);
     mpp[mp(i,u)]=w;
     mpp[mp(u,i)]=w;
  }
  dfs(1,0);
  for(i=1;i<=n;i++)
    cout<<ans[i]<<" ";
  return 0;
}


#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define PI 3.14159265
#define cbrt cbrtl
using namespace std;
map< pair<ll,ll> ,ll> mpp;
ll n;
vector<ll> adj[200005];
ll par[200005][25];
ll dep[200005],a[200005],val[200005];
void dfs(ll u,ll p)
{
  ll i;
  par[u][0]=p;
  dep[u]=dep[p];
  if(p!=0)
    dep[u]+=mpp[mp(u,p)];
  for(i=0;i<adj[u].size();i++)
  {
    ll x=adj[u][i];
    if(x!=p)
      dfs(x,u);
  }
}
ll dfs1(ll u,ll p,ll sum)
{
  ll i;
  for(i=0;i<adj[u].size();i++)
  {
    ll x=adj[u][i];
    if(x!=p)
    {
      ll y=dfs1(x,u,sum);
      val[u]+=y;
    }
  }
  return val[u];
}
void compute()
{
   ll i,j;
   for(i=1;i<25;i++)
    for(j=1;j<=n;j++)
      if(par[j][i-1]!=-1)
        par[j][i]=par[par[j][i-1]][i-1];
}
void solve(ll node)
{
  ll i;
  ll t=node;
  while(1)
  {
     ll t1=t;
     for(i=0;i<25;i++)
     if(par[t][i]!=-1)
     {
        if(dep[par[t][i]]<dep[node]-a[node])
          break;
        t1=par[t][i];
     }
     else
       break;
     if(t1==t)
       break;
     t=t1;
  }
  if(t==0)
    t++;
  val[par[node][0]]+=1;
  val[par[t][0]]-=1;
}
int main()
{
  memset(par,-1,sizeof(par));
  cin>>n;
  ll i;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(i=2;i<=n;i++)
  {
     ll u,w;
     cin>>u>>w;
     adj[i].pb(u);
     adj[u].pb(i);
     mpp[mp(i,u)]=w;
     mpp[mp(u,i)]=w;
  }
  dfs(1,0);
  compute();
  for(i=1;i<=n;i++)
    solve(i);
  dfs1(1,0,0);
  for(i=1;i<=n;i++)
    cout<<val[i]<<" ";
  return 0;
}


#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define PI 3.14159265
#define cbrt cbrtl
using namespace std;
map< pair<ll,ll> ,ll> mpp;
ll n;
vector<ll> adj[200005];
ll dep[200005],a[200005],ans[200005];
vector< pair<ll,ll> > dfs(ll u,ll p)
{
  dep[u]=dep[p];
  if(p!=0)
    dep[u]+=mpp[mp(p,u)];
  ll i;
  vector< pair<ll,ll> > temp;
  temp.clear();
  for(i=0;i<adj[u].size();i++)
  {
    ll x=adj[u][i];
    if(x!=p)
    {
      vector < pair<ll,ll> > t=dfs(x,u);
      temp.insert(temp.begin(),t.begin(),t.end());
    }
  }
  sort(all(temp));
  ll l=0,r=temp.size()-1,mid;
  ll val=-1;
  while(l<=r)
  {
    mid=(l+r)/2;
    if(temp[mid].ff<=dep[u])
    {
       val=mid;
       l=mid+1;
    }
    else
      r=mid-1;
  }
  ans[u]=val+1;
  temp.pb(mp(dep[u]-a[u],u));
  return temp;
}
int main()
{
  cin>>n;
  ll i;
  for(i=1;i<=n;i++)
    cin>>a[i];
  for(i=2;i<=n;i++)
  {
     ll u,w;
     cin>>u>>w;
     adj[i].pb(u);
     adj[u].pb(i);
     mpp[mp(i,u)]=w;
     mpp[mp(u,i)]=w;
  }
  dfs(1,0);
  for(i=1;i<=n;i++)
    cout<<ans[i]<<" ";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define DB pop_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define V(a) vector<a>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
template<typename T>
void pairsort(T a[],T b[],ll n);
ll logint(ll x,ll y);
void Miden(ll **p1,ll n);
void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m);
void Mpow(ll **p1,ll **ans,ll n,ll y,ll m);
pll Egcd(ll x,ll y);

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

pll Egcd(ll x,ll y)
{
    if(x==0) return MP(0,1);
    pll t=Egcd(y%x,x);
    return MP(t.S-t.F*(y/x),t.F);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

template<typename T>
void pairsort(T a[],T b[],ll n)
{
    pair<T,T> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    REP(i,0,x)
    {
        REP(j,0,z)
        {
            c[i][j]=0;
            REP(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

priority_queue<ll> dfs(ll x,V(ll) &path,ll p[],V(pll) ad[],ll sum,ll a[],ll ans[])
{
    path.PB(sum);
    ll l=0,r=path.size()-1;
    while(l<r)
    {
        if((sum-path[(l+r)/2])<=a[x])
        {
            r=(l+r)/2;
        }
        else
        {
            l=(l+r)/2+1;
        }
    }
    priority_queue<ll> st;
    for(auto it:ad[x])
    {
        priority_queue<ll> v=dfs(it.F,path,p,ad,sum+it.S,a,ans);
        while(v.size()>0)
        {
            st.push(v.top());
            v.pop();
        }
    }
    path.DB();
    st.push(l);
    while(st.top()>path.size())
    {
        st.pop();
    }
    ans[x]=st.size()-1;
    return st;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll ntc=1;
    //cin>>ntc;
    REP(tc,1,ntc+1)
    {
        //cout<<"Case #"<<tc<<": ";

        ll n;
        cin>>n;
        ll a[n];
        ll p[n];
        V(pll) ad[n];
        p[0]=0;
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
        }
        REP(i,1,n)
        {
            ll t1,t2;
            cin>>t1>>t2;
            t1--;
            p[i]=t1;
            ad[t1].PB(MP(i,t2));
        }
        ll ans[n];
        V(ll) path;
        dfs(0,path,p,ad,0,a,ans);
        REP(i,0,n)
        {
            cout<<ans[i]<<' ';
        }

        cout<<'\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define DB pop_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define V(a) vector<a>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
template<typename T>
void pairsort(T a[],T b[],ll n);
ll logint(ll x,ll y);
void Miden(ll **p1,ll n);
void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m);
void Mpow(ll **p1,ll **ans,ll n,ll y,ll m);
pll Egcd(ll x,ll y);

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

pll Egcd(ll x,ll y)
{
    if(x==0) return MP(0,1);
    pll t=Egcd(y%x,x);
    return MP(t.S-t.F*(y/x),t.F);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

template<typename T>
void pairsort(T a[],T b[],ll n)
{
    pair<T,T> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    REP(i,0,x)
    {
        REP(j,0,z)
        {
            c[i][j]=0;
            REP(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

priority_queue<ll> dfs(ll x,V(ll) &path,ll p[],V(pll) ad[],ll sum,ll a[],ll ans[])
{
    path.PB(sum);
    ll l=0,r=path.size()-1;
    while(l<r)
    {
        if((sum-path[(l+r)/2])<=a[x])
        {
            r=(l+r)/2;
        }
        else
        {
            l=(l+r)/2+1;
        }
    }
    V(priority_queue<ll>) v;
    priority_queue<ll> tempemp;
    v.PB(tempemp);
    ll mxi=0;
    for(auto it:ad[x])
    {
        v.PB(dfs(it.F,path,p,ad,sum+it.S,a,ans));
        if(v[v.size()-1].size()>v[mxi].size())
        {
            mxi=v.size()-1;
        }
    }
    REP(i,0,v.size())
    {
        if(i!=mxi)
        {
            while(v[i].size()>0)
            {
                v[mxi].push(v[i].top());
                v[i].pop();
            }
        }
    }
    path.DB();
    v[mxi].push(l);
    while(v[mxi].top()>path.size())
    {
        v[mxi].pop();
    }
    ans[x]=v[mxi].size()-1;
    return v[mxi];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll ntc=1;
    //cin>>ntc;
    REP(tc,1,ntc+1)
    {
        //cout<<"Case #"<<tc<<": ";

        ll n;
        cin>>n;
        ll a[n];
        ll p[n];
        V(pll) ad[n];
        p[0]=0;
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
        }
        REP(i,1,n)
        {
            ll t1,t2;
            cin>>t1>>t2;
            t1--;
            p[i]=t1;
            ad[t1].PB(MP(i,t2));
        }
        ll ans[n];
        V(ll) path;
        dfs(0,path,p,ad,0,a,ans);
        REP(i,0,n)
        {
            cout<<ans[i]<<' ';
        }

        cout<<'\n';
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M1 1000000007
#define M2 998244353
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define DB pop_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define V(a) vector<a>

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
template<typename T>
void pairsort(T a[],T b[],ll n);
ll logint(ll x,ll y);
void Miden(ll **p1,ll n);
void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m);
void Mpow(ll **p1,ll **ans,ll n,ll y,ll m);
pll Egcd(ll x,ll y);

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

pll Egcd(ll x,ll y)
{
    if(x==0) return MP(0,1);
    pll t=Egcd(y%x,x);
    return MP(t.S-t.F*(y/x),t.F);
}

ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

template<typename T>
void pairsort(T a[],T b[],ll n)
{
    pair<T,T> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}

ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}

void Miden(ll **p1,ll n)
{
    ll (*x)[n]=(ll(*)[n]) p1;
    REP(i,0,n)
    {
        REP(j,0,n)
        {
            x[i][j]=0;
        }
        x[i][i]=1;
    }
    return;
}

void Mmult(ll **p1,ll **p2,ll **ans,ll x,ll y,ll z,ll m)
{
    ll (*a)[y]=(ll (*)[y])p1;
    ll (*b)[z]=(ll (*)[z])p2;
    ll (*c)[z]=(ll (*)[z])ans;
    REP(i,0,x)
    {
        REP(j,0,z)
        {
            c[i][j]=0;
            REP(k,0,y)
            {
                c[i][j]+=a[i][k]*b[k][j];
                c[i][j]%=m;
            }
        }
    }
    return;
}

void Mpow(ll **p1,ll **ans,ll n,ll y,ll m)
{
    if(y==0)
    {
        Miden(ans,n);
        return;
    }
    ll t[n][n];
    Mpow(p1,(ll **)t,n,y/2,m);
    ll z[n][n];
    Mmult((ll **)t,(ll **)t,(ll **)z,n,n,n,m);
    if(y%2)
    {
        Mmult((ll **)z,p1,ans,n,n,n,m);
    }
    else
    {
        Miden((ll **)t,n);
        Mmult((ll **)z,(ll **)t,ans,n,n,n,m);
    }
    return;
}

ll dfs(ll x,V(ll) &path,ll p[],V(pll) ad[],ll sum,ll a[],ll ans[],priority_queue<ll> v[])
{
    path.PB(sum);
    ll l=0,r=path.size()-1;
    while(l<r)
    {
        if((sum-path[(l+r)/2])<=a[x])
        {
            r=(l+r)/2;
        }
        else
        {
            l=(l+r)/2+1;
        }
    }
    V(ll) vt;
    ll mxi=x;
    for(auto it:ad[x])
    {
        vt.PB(dfs(it.F,path,p,ad,sum+it.S,a,ans,v));
        if(v[vt[vt.size()-1]].size()>v[mxi].size())
        {
            mxi=vt[vt.size()-1];
        }
    }
    REP(i,0,vt.size())
    {
        if(vt[i]!=mxi)
        {
            while(v[vt[i]].size()>0)
            {
                v[mxi].push(v[vt[i]].top());
                v[vt[i]].pop();
            }
        }
    }
    path.DB();
    v[mxi].push(l);
    while(v[mxi].top()>path.size())
    {
        v[mxi].pop();
    }
    ans[x]=v[mxi].size()-1;
    return mxi;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */

    ll ntc=1;
    //cin>>ntc;
    REP(tc,1,ntc+1)
    {
        //cout<<"Case #"<<tc<<": ";

        ll n;
        cin>>n;
        ll a[n];
        ll p[n];
        V(pll) ad[n];
        p[0]=0;
        REP(i,0,n)
        {
            ll t;
            cin>>t;
            a[i]=t;
        }
        REP(i,1,n)
        {
            ll t1,t2;
            cin>>t1>>t2;
            t1--;
            p[i]=t1;
            ad[t1].PB(MP(i,t2));
        }
        ll ans[n];
        V(ll) path;
        priority_queue<ll> v[n];
        dfs(0,path,p,ad,0,a,ans,v);
        REP(i,0,n)
        {
            cout<<ans[i]<<' ';
        }

        cout<<'\n';
    }

    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int >
#define all(a) (a).begin(), (a).end()

using namespace std;

const int maxn = 1e3 + 10;

int n;
int A[ maxn ];
vector < ii > graph[ maxn ];
int val[ maxn ];
int sol[ maxn ];
int par[ maxn ];

vector < ii > path;

void dfs( int node, int w ) {
	if ( node ) {
		int lo = 0, hi = path.size() - 1, ans = -1;
		while ( lo <= hi ) {
			int mid = lo + ( hi - lo ) / 2;
			if ( ( w - path[ mid ].y ) <= A[ node ] ) {
				ans = path[ mid ].x;hi = mid - 1;
			} else lo = mid + 1;
		}

		if ( ans != -1 ) {
			val[ par[ node ] ]++;
			if ( ans ) val[ par[ ans ] ]--;
		}
	}
	path.pb( { node, w } );

	for( auto p : graph[ node ] ) {
		int where = p.x;
		int d = p.y;
		dfs( where, w + d );
	}
	path.pop_back();
}

void find( int node ) {
	sol[ node ] += val[ node ];
	for( auto p : graph[ node ] ) {
		int where = p.x;
		find( where );
		sol[ node ] += sol[ where ];
	}
}

int main() {
	cin >> n;
	for( int i = 0;i < n;i++ ) {
		cin >> A[ i ];
	}
	par[ 0 ] = -1;
	for( int i = 1;i < n;i++ ) {
		int x, y;cin >> x >> y;
		x--;
		par[ i ] = x;
		graph[ x ].pb( { i, y } );
	}

	dfs( 0, 0 );
	find( 0 );
	for( int i = 0;i < n;i++ ) cout << sol[ i ] << " ";
	cout << "\n";
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int >
#define all(a) (a).begin(), (a).end()

using namespace std;

const int maxn = 2e5 + 10;

int n;
int A[ maxn ];
vector < ii > graph[ maxn ];
int val[ maxn ];
int sol[ maxn ];
int par[ maxn ];

vector < ii > path;

void dfs( int node, int w ) {
	if ( node ) {
		int lo = 0, hi = path.size() - 1, ans = -1;
		while ( lo <= hi ) {
			int mid = lo + ( hi - lo ) / 2;
			if ( ( w - path[ mid ].y ) <= A[ node ] ) {
				ans = path[ mid ].x;hi = mid - 1;
			} else lo = mid + 1;
		}

		if ( ans != -1 ) {
			val[ par[ node ] ]++;
			if ( ans ) val[ par[ ans ] ]--;
		}
	}
	path.pb( { node, w } );

	for( auto p : graph[ node ] ) {
		int where = p.x;
		int d = p.y;
		dfs( where, w + d );
	}
	path.pop_back();
}

void find( int node ) {
	sol[ node ] += val[ node ];
	for( auto p : graph[ node ] ) {
		int where = p.x;
		find( where );
		sol[ node ] += sol[ where ];
	}
}

int main() {
	cin >> n;
	for( int i = 0;i < n;i++ ) {
		cin >> A[ i ];
	}
	par[ 0 ] = -1;
	for( int i = 1;i < n;i++ ) {
		int x, y;cin >> x >> y;
		x--;
		par[ i ] = x;
		graph[ x ].pb( { i, y } );
	}

	dfs( 0, 0 );
	find( 0 );
	for( int i = 0;i < n;i++ ) cout << sol[ i ] << " ";
	cout << "\n";
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int >
#define all(a) (a).begin(), (a).end()

using namespace std;

const int maxn = 2e5 + 10;

int n;
ll A[ maxn ];
vector < pair < int, ll > > graph[ maxn ];
int val[ maxn ];
int sol[ maxn ];
int par[ maxn ];

vector < pair < int, ll > > path;

void dfs( int node, ll w ) {
	if ( node ) {
		int lo = 0, hi = path.size() - 1, ans = -1;
		while ( lo <= hi ) {
			int mid = lo + ( hi - lo ) / 2;
			if ( ( w - path[ mid ].y ) <= A[ node ] ) {
				ans = path[ mid ].x;hi = mid - 1;
			} else lo = mid + 1;
		}

		if ( ans != -1 ) {
			val[ par[ node ] ]++;
			if ( ans ) val[ par[ ans ] ]--;
		}
	}
	path.pb( { node, w } );

	for( auto p : graph[ node ] ) {
		int where = p.x;
		int d = p.y;
		dfs( where, w + d );
	}
	path.pop_back();
}

void find( int node ) {
	sol[ node ] += val[ node ];
	for( auto p : graph[ node ] ) {
		int where = p.x;
		find( where );
		sol[ node ] += sol[ where ];
	}
}

int main() {
	cin >> n;
	for( int i = 0;i < n;i++ ) {
		cin >> A[ i ];
	}
	par[ 0 ] = -1;
	for( int i = 1;i < n;i++ ) {
		int x;
		ll y;
		cin >> x >> y;
		x--;
		par[ i ] = x;
		graph[ x ].pb( { i, y } );
	}

	dfs( 0, 0 );
	find( 0 );
	for( int i = 0;i < n;i++ ) cout << sol[ i ] << " ";
	cout << "\n";
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ii pair < int, int >
#define vi vector < int >
#define all(a) (a).begin(), (a).end()

using namespace std;

const int maxn = 2e5 + 10;

int n;
ll A[ maxn ];
vector < pair < int, ll > > graph[ maxn ];
int val[ maxn ];
int sol[ maxn ];
int par[ maxn ];

vector < ii > path;

void dfs( int node, ll w ) {
	if ( node ) {
		int lo = 0, hi = path.size() - 1, ans = -1;
		while ( lo <= hi ) {
			int mid = lo + ( hi - lo ) / 2;
			if ( ( w - path[ mid ].y ) <= A[ node ] ) {
				ans = path[ mid ].x;hi = mid - 1;
			} else lo = mid + 1;
		}

		if ( ans != -1 ) {
			val[ par[ node ] ]++;
			if ( ans ) val[ par[ ans ] ]--;
		}
	}
	path.pb( { node, w } );

	for( auto p : graph[ node ] ) {
		int where = p.x;
		int d = p.y;
		dfs( where, w + d );
	}
	path.pop_back();
}

void find( int node ) {
	sol[ node ] += val[ node ];
	for( auto p : graph[ node ] ) {
		int where = p.x;
		find( where );
		sol[ node ] += sol[ where ];
	}
}

int main() {
	cin >> n;
	for( int i = 0;i < n;i++ ) {
		cin >> A[ i ];
	}
	par[ 0 ] = -1;
	for( int i = 1;i < n;i++ ) {
		int x;
		ll y;
		cin >> x >> y;
		x--;
		par[ i ] = x;
		graph[ x ].pb( { i, y } );
	}

	dfs( 0, 0 );
	find( 0 );
	for( int i = 0;i < n;i++ ) cout << sol[ i ] << " ";
	cout << "\n";
	return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[200005];
pair<int,int> parent[200005];
vector<pair<int,int> > edgeList[200005];
long long pSum[200005];
int BinLift[200005][21];
int ans[200005];
int ansNode[200005];
void printAns(int node,int temps)
{
    if(node == 0)
        return;
    temps += ans[node];
    ansNode[node] = temps;
    printAns(parent[node].first,temps);
}
void DFS(int idx,int parent,long long sum)
{
    BinLift[idx][0] = parent;
    for(int i = 1;i <= 20;i++)
        BinLift[idx][i] = BinLift[BinLift[idx][i-1]][i-1];
    pSum[idx] = sum;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i].first,idx,sum + edgeList[idx][i].second);
}
int getAncestor(int x,int kth)
{
    for(int i = 20;i >= 0;i--)
    {
        if(kth & (1 << i))
        {
            kth -= (1 << i);
            x = BinLift[x][i];
        }
    }
    return x;
}
int clarify(int x,int kth)
{
    while(getAncestor(x,kth) <= 0)
        kth--;
    while(kth >= 0 && pSum[x] - pSum[getAncestor(x,kth)] > arr[x])
        kth--;
    return kth;
}
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = 2;i <= n;i++)
    {
        int p,w;
        cin >> p >> w;
        parent[i] = make_pair(p,w);
        edgeList[p].push_back(make_pair(i,w));
    }
    DFS(1,0,0);
    for(int i = 1;i <= n;i++)
    {
        int lo = 0;
        int hi = 2e5+5;
        while(lo < hi)
        {
            int mid = (lo+hi)/2;
            int kthAnc = getAncestor(i,mid);
            if(kthAnc <= 0)
            {
                hi = mid-1;
                continue;
            }
            long long s = pSum[i] - pSum[kthAnc];
            if(s <= arr[i])
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        lo = clarify(i,lo);
        if(lo > 0){
        cout << getAncestor(i,1) << " " << getAncestor(i,lo+1) << endl;
        ans[getAncestor(i,1)]++;
        ans[getAncestor(i,lo+1)]--;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        if(edgeList[i].size() == 0)
            printAns(i,0);
    }
    for(int i = 1;i <= n;i++)
        cout << max(0,ansNode[i]) << " ";
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[200005];
pair<int,int> parent[200005];
vector<pair<int,int> > edgeList[200005];
long long pSum[200005];
int BinLift[200005][21];
int ans[200005];
int ansNode[200005];
void printAns(int node,int temps)
{
    if(node == 0)
        return;
    temps += ans[node];
    ansNode[node] = temps;
    printAns(parent[node].first,temps);
}
void DFS(int idx,int parent,long long sum)
{
    BinLift[idx][0] = parent;
    for(int i = 1;i <= 20;i++)
        BinLift[idx][i] = BinLift[BinLift[idx][i-1]][i-1];
    pSum[idx] = sum;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i].first,idx,sum + edgeList[idx][i].second);
}
int getAncestor(int x,int kth)
{
    for(int i = 20;i >= 0;i--)
    {
        if(kth & (1 << i))
        {
            kth -= (1 << i);
            x = BinLift[x][i];
        }
    }
    return x;
}
int clarify(int x,int kth)
{
    while(getAncestor(x,kth) <= 0)
        kth--;
    while(kth >= 0 && pSum[x] - pSum[getAncestor(x,kth)] > arr[x])
        kth--;
    return kth;
}
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = 2;i <= n;i++)
    {
        int p,w;
        cin >> p >> w;
        parent[i] = make_pair(p,w);
        edgeList[p].push_back(make_pair(i,w));
    }
    DFS(1,0,0);
    for(int i = 1;i <= n;i++)
    {
        int lo = 0;
        int hi = 2e5+5;
        while(lo < hi)
        {
            int mid = (lo+hi)/2;
            int kthAnc = getAncestor(i,mid);
            if(kthAnc <= 0)
            {
                hi = mid-1;
                continue;
            }
            long long s = pSum[i] - pSum[kthAnc];
            if(s <= arr[i])
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        lo = clarify(i,lo);
        if(lo > 0){
       // cout << getAncestor(i,1) << " " << getAncestor(i,lo+1) << endl;
        ans[getAncestor(i,1)]++;
        ans[getAncestor(i,lo+1)]--;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        if(edgeList[i].size() == 0)
            printAns(i,0);
    }
    for(int i = 1;i <= n;i++)
        cout << max(0,ansNode[i]) << " ";
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[200005];
pair<int,int> parent[200005];
vector<pair<int,int> > edgeList[200005];
long long pSum[200005];
int BinLift[200005][21];
int ans[200005];
int ansNode[200005];
int printAns(int node)
{
    int C = ans[node];
    for(int i = 0;i < edgeList[node].size();i++)
        C += printAns(edgeList[node][i].first);
    ansNode[node] = C;
    return C;
}
void DFS(int idx,int parent,long long sum)
{
    BinLift[idx][0] = parent;
    for(int i = 1;i <= 20;i++)
        BinLift[idx][i] = BinLift[BinLift[idx][i-1]][i-1];
    pSum[idx] = sum;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i].first,idx,sum + edgeList[idx][i].second);
}
int getAncestor(int x,int kth)
{
    for(int i = 20;i >= 0;i--)
    {
        if(kth & (1 << i))
        {
            kth -= (1 << i);
            x = BinLift[x][i];
        }
    }
    return x;
}
int clarify(int x,int kth)
{
    while(getAncestor(x,kth) <= 0)
        kth--;
    while(kth >= 0 && pSum[x] - pSum[getAncestor(x,kth)] > arr[x])
        kth--;
    return kth;
}
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = 2;i <= n;i++)
    {
        int p,w;
        cin >> p >> w;
        parent[i] = make_pair(p,w);
        edgeList[p].push_back(make_pair(i,w));
    }
    DFS(1,0,0);
    for(int i = 1;i <= n;i++)
    {
        int lo = 0;
        int hi = 2e5+5;
        while(lo < hi)
        {
            int mid = (lo+hi)/2;
            int kthAnc = getAncestor(i,mid);
            if(kthAnc <= 0)
            {
                hi = mid-1;
                continue;
            }
            long long s = pSum[i] - pSum[kthAnc];
            if(s <= arr[i])
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        lo = clarify(i,lo);
        if(lo > 0){
            ans[getAncestor(i,1)]++;
            ans[getAncestor(i,lo+1)]--;
        }
    }
    printAns(1);
    for(int i = 1;i <= n;i++)
        cout << ansNode[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[200005];
pair<int,int> parent[200005];
vector<pair<int,int> > edgeList[200005];
long long pSum[200005];
int BinLift[200005][21];
int ans[200005];
int ansNode[200005];
void printAns(int node,int temps)
{
    if(node == 0)
        return;
    temps += ans[node];
    ansNode[node] += temps;
    printAns(parent[node].first,temps);
}
void DFS(int idx,int parent,long long sum)
{
    BinLift[idx][0] = parent;
    for(int i = 1;i <= 20;i++)
        BinLift[idx][i] = BinLift[BinLift[idx][i-1]][i-1];
    pSum[idx] = sum;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i].first,idx,sum + edgeList[idx][i].second);
}
int getAncestor(int x,int kth)
{
    for(int i = 20;i >= 0;i--)
    {
        if(kth & (1 << i))
        {
            kth -= (1 << i);
            x = BinLift[x][i];
        }
    }
    return x;
}
int clarify(int x,int kth)
{
    while(getAncestor(x,kth) <= 0)
        kth--;
    while(kth >= 0 && pSum[x] - pSum[getAncestor(x,kth)] > arr[x])
        kth--;
    return kth;
}
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = 2;i <= n;i++)
    {
        int p,w;
        cin >> p >> w;
        parent[i] = make_pair(p,w);
        edgeList[p].push_back(make_pair(i,w));
    }
    DFS(1,0,0);
    for(int i = 1;i <= n;i++)
    {
        int lo = 0;
        int hi = 2e5+5;
        while(lo < hi)
        {
            int mid = (lo+hi)/2;
            int kthAnc = getAncestor(i,mid);
            if(kthAnc <= 0)
            {
                hi = mid-1;
                continue;
            }
            long long s = pSum[i] - pSum[kthAnc];
            if(s <= arr[i])
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        lo = clarify(i,lo);
        if(lo > 0){
        int x = getAncestor(i,1);
        while(x != getAncestor(i,lo+1))
            ansNode[x]++,x = getAncestor(x,1);
        }
    }
    for(int i = 1;i <= n;i++)
        cout << ansNode[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long fastpow(long long x,long long k)
{
    if(!k)
        return 1;
    if(k & 1)
        return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
    long long ans = fastpow(x,k/2);
    ans %= MOD;
    ans *= ans;
    ans %= MOD;
    return ans;
}
long long sumF(long long x)
{
    int s = 0;
    while(x)
        s += x%10,x /= 10;
    return s;
}
int arr[200005];
pair<int,int> parent[200005];
vector<pair<int,int> > edgeList[200005];
long long pSum[200005];
int BinLift[200005][21];
int ans[200005];
int ansNode[200005];
void printAns(int node,int temps)
{
    if(node == 0)
        return;
    temps += ans[node];
    ansNode[node] = temps;
    printAns(parent[node].first,temps);
}
void DFS(int idx,int parent,long long sum)
{
    BinLift[idx][0] = parent;
    for(int i = 1;i <= 20;i++)
        BinLift[idx][i] = BinLift[BinLift[idx][i-1]][i-1];
    pSum[idx] = sum;
    for(int i = 0;i < edgeList[idx].size();i++)
        DFS(edgeList[idx][i].first,idx,sum + edgeList[idx][i].second);
}
int getAncestor(int x,int kth)
{
    for(int i = 20;i >= 0;i--)
    {
        if(kth & (1 << i))
        {
            kth -= (1 << i);
            x = BinLift[x][i];
        }
    }
    return x;
}
int clarify(int x,int kth)
{
    while(getAncestor(x,kth) <= 0)
        kth--;
    while(kth >= 0 && pSum[x] - pSum[getAncestor(x,kth)] > arr[x])
        kth--;
    return kth;
}
int main()
{
    IO;
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++)
        cin >> arr[i];
    for(int i = 2;i <= n;i++)
    {
        int p,w;
        cin >> p >> w;
        parent[i] = make_pair(p,w);
        edgeList[p].push_back(make_pair(i,w));
    }
    DFS(1,0,0);
    for(int i = 1;i <= n;i++)
    {
        int lo = 0;
        int hi = 2e5+5;
        while(lo < hi)
        {
            int mid = (lo+hi)/2;
            int kthAnc = getAncestor(i,mid);
            if(kthAnc <= 0)
            {
                hi = mid-1;
                continue;
            }
            long long s = pSum[i] - pSum[kthAnc];
            if(s <= arr[i])
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        lo = clarify(i,lo);
        if(lo > 0){
        ans[getAncestor(i,1)]++;
        ans[getAncestor(i,lo+1)]--;
        }
    }
    for(int i = 1;i <= n;i++)
    {
        if(edgeList[i].size() == 0)
            printAns(i,0);
    }
    for(int i = 1;i <= n;i++)
        cout << ansNode[i] << " ";
    return 0;
}


#include <bits/stdc++.h>
//#pragma warning (error: 6260)
#define FOR(i,x,y) for(int i = (x) ; i < (y) ; ++i)
#define FORD(i,x,y) for(int i = (x) ; i > (y) ; --i)
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;

struct Edge{
	int v;
	ll val;
};
vector<Edge> G[maxn];
ll a[maxn];
ll ans[maxn];

ll v[maxn];
int ind[maxn];

void dfs(int x ,ll val, int dep)
{
	ans[x] = 0;

	v[dep] = val;
	ind[dep] = x;

	for (Edge & e : G[x])
	{
		dfs(e.v,val + e.val, dep+1);
		ans[x] += ans[e.v];
 	}

	int p = lower_bound(v,v+dep,v[dep]-a[x]) - v;

	ans[x]++;
	if(p)
		ans[ind[p-1]]--;

}

int main()
{
	int x; ll y;
	int n;
	cin >> n;

	FOR(i,1,n+1) scanf("%lld",a+i);
	//build tree
	FOR(i,2,n+1)
	{
		scanf("%d%lld",&x,&y);
		G[x].push_back(Edge{i,y});
	}
	dfs(1,0,0);
	FOR(i,1,n+1)
		cout << ans[i] -1 << ' ';

	return 0;

}


#include <bits/stdc++.h>
#pragma warning (error: 6260)
#define FOR(i,x,y) for(int i = (x) ; i < (y) ; ++i)
#define FORD(i,x,y) for(int i = (x) ; i > (y) ; --i)
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;

struct Edge{
	int v;
	ll val;
};
vector<Edge> G[maxn];
ll a[maxn];
ll ans[maxn];

ll v[maxn];
int ind[maxn];

void dfs(int x ,ll val, int dep)
{
	ans[x] = 0;

	v[dep] = val;
	ind[dep] = x;

	for (Edge & e : G[x])
	{
		dfs(e.v,val + e.val, dep+1);
		ans[x] += ans[e.v];
 	}

	int p = lower_bound(v,v+dep,v[dep]-a[x]) - v;

	ans[x]++;
	if(p)
		ans[ind[p-1]]--;

}

int main()
{
	int x; ll y;
	int n;
	cin >> n;

	FOR(i,1,n+1) scanf("%lld",a+i);
	//build tree
	FOR(i,2,n+1)
	{
		scanf("%d%d",&x,&y);
		G[x].push_back(Edge{i,y});
	}
	dfs(1,0,0);
	FOR(i,1,n+1)
		cout << ans[i] -1 << ' ';

	return 0;

}


#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i = (x) ; i < (y) ; ++i)
#define FORD(i,x,y) for(int i = (x) ; i > (y) ; --i)
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;

struct Edge{
	int v;
	ll val;
};
vector<Edge> G[maxn];
ll a[maxn];
ll ans[maxn];

int v[maxn];
int ind[maxn];

void dfs(int x ,ll val, int dep)
{
	ans[x] = 0;

	v[dep] = val;
	ind[dep] = x;

	for (Edge & e : G[x])
	{
		dfs(e.v,val + e.val, dep+1);
		ans[x] += ans[e.v];
 	}

	int p = lower_bound(v,v+dep,v[dep]-a[x]) - v;

	ans[x]++;
	if(p)
		ans[ind[p-1]]--;

}

int main()
{
	int x; ll y;
	int n;
	cin >> n;

	FOR(i,1,n+1) scanf("%lld",a+i);
	//build tree
	FOR(i,2,n+1)
	{
		scanf("%d%d",&x,&y);
		G[x].push_back(Edge{i,y});
	}
	dfs(1,0,0);
	FOR(i,1,n+1)
		cout << ans[i] -1 << ' ';

	return 0;

}