#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

const int MaxN = 2e5;
typedef long long LL;
using namespace std;

vector < pair <int, int> > G[MaxN + 5];
LL dis[MaxN + 5];
vector <LL> V;
int cur = 0, tot;
int rt[2 * MaxN + 5], a[MaxN + 5];
int L[MaxN + 5], R[MaxN + 5];
int seq[MaxN + 5];

struct NODE {
	int l, r, cnt;
}tr[MaxN * 80 + 5];

void Dfs(int x, LL d)
{
	seq[++tot] = x; L[x] = tot;
	dis[x] = d;
	for (auto v : G[x]) {
		Dfs(v.first, d + v.second);
	}
	R[x] = tot;
}

void Push_up(int o)
{
	tr[o].cnt = tr[tr[o].l].cnt + tr[tr[o].r].cnt;
}

int Build(int l, int r)
{
	int k = cur++;
	if(l == r) {
		tr[k].cnt = 0; return k;
	}
	int mid = (l + r) >> 1;
	tr[k].l = Build(l, mid);
	tr[k].r = Build(mid + 1, r);
	Push_up(k); return k;
}

int Update(int o, int l, int r, int pos, int val)
{
	int k = cur++;
	tr[k] = tr[o];
	if(l == pos && r == pos) {
		tr[k].cnt += val; return k;
	}
	int mid = (l + r) >> 1;
	if(pos <= mid) tr[k].l = Update(tr[o].l, l, mid, pos, val);
	else tr[k].r = Update(tr[o].r, mid + 1, r, pos, val);
	Push_up(k); return k;
}

int Query(int l, int r, int o, int v, int pos)
{
	if(l == r) return tr[v].cnt - tr[o].cnt;
	int mid = (l + r) >> 1;
	if(pos <= mid) return Query(l, mid, tr[o].l, tr[v].l, pos);
	else return (tr[tr[v].l].cnt - tr[tr[o].l].cnt + Query(mid + 1, r, tr[o].r, tr[v].r, pos));
}

int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 2; i <= n; i++) {
		int fa, w; scanf("%d%d", &fa, &w);
		G[fa].push_back(make_pair(i, w));
	}
	dis[1] = 0;
	Dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		V.push_back(dis[i]);
		dis[i] -= a[i];
		V.push_back(dis[i]);
	}
	sort (V.begin(), V.end()); V.resize(unique(V.begin(), V.end()) - V.begin());
	seq[0] = 0;
	rt[0] = Build(1, (int)V.size());
	int all = V.size();
	for (int i = 1; i <= n; i++) {
		int p = lower_bound(V.begin(), V.end(), dis[seq[i]]) - V.begin() + 1;
		rt[i] = Update(rt[i - 1], 1, all, p, 1);
	}
	for (int i = 1; i <= n; i++) {
		int res = 0; int p = lower_bound(V.begin(), V.end(), dis[i] + a[i]) - V.begin() + 1;
		printf("%d%c", Query(1, all, rt[L[i] - 1], rt[R[i]], p) - 1, i == n ? '\n' : ' ');
	}
	return 0;
}


#include <bits/stdc++.h> /**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ios ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define ll long long
#define ld long double
const int nax = 2*1e5+10;
int n;
int a[nax];
int pr[nax];
vector<pair<int,ll>> tree[nax];
int son[nax];
int dp[nax];
set<pair<ll,int>> prv;
void dfs(int u, ll sum){
	if((int)prv.size()){
		auto it = *prv.lower_bound({sum-a[u],-1});
		//cout<<"sum: "<<sum<<" "<<a[u]<<endl;
		//cout<<"look for: "<<sum-a[u]<<" "<<-1<<endl;
		//cout<<"found: "<<it.first<<" "<<it.second<<endl;
		int p = 0;
		if( prv.count(it) ){
			p = pr[it.second];
		}else{
			p = pr[u];
		}
		//cout<<"u: "<<u<<" prev: "<<p<<endl;
		//cout<<endl;
		dp[p]--;
	}
	prv.insert({sum,u});
	for(auto v : tree[u]){
		dfs(v.first,sum+v.second);
	}
	prv.erase(prv.find({sum,u}));
}
int go(int u){
	int ans = 0;
	for(auto v : tree[u]){
		ans += go(v.first);
	}
	son[u] = ans+dp[u];
	return son[u] + 1;
}
int main(){
	ios;
	#ifdef LOCAL_JUDGE
		//freopen("in.txt", "rt", stdin);
		//freopen("out.txt", "w", stdout);
	#endif
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	pr[1]=0;
	for(int i=2; i<=n; i++){
		int p;
		ll w;
		cin>>p>>w;
		pr[i] = p;
		tree[p].push_back({i,w});
	}
	dfs(1,0ll);
	go(1);
	for(int i=1; i<=n; i++) cout<<son[i]<<" ";
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

vector<int> a, ans;
vector<int> path; // nodes on path to root
vector<long long> dfr; // distance from root of each node on path
vector<int> noControlV; // number of nodes whose highest controller is the child of this node (for each node on path)
vector< vector< pair<int, int> > > children;

void dfs(int node, long long dfr_node) {
    // now dfs from children and calculate how many vertices node controls
    path.push_back(node);
    dfr.push_back(dfr_node);
    noControlV.push_back(0);

    for (pair<int, int> child : children[node]) {
        dfs(child.first, dfr_node + child.second);
        ans[node] += ans[child.first];
        if (child.second <= a[child.first]) ++ans[node];
    }
    ans[node] -= noControlV.back();

    path.pop_back();
    dfr.pop_back();
    noControlV.pop_back();

    // find the furthest ancestor up from this node which controls this one, and then tell its parent that it does not control this one
    int left = -1, right = path.size();
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (dfr[mid] >= dfr_node - a[node]) right = mid;
        else left = mid;
    }
    if (left != -1 && left != (int)path.size()-1) ++noControlV[left];
}

int main() {
    int n; cin >> n;
    a.resize(1+n), ans.resize(1+n), children.resize(1+n);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 2; i <= n; ++i) {
        int parent, weight; cin >> parent >> weight;
        children[parent].push_back({i, weight});
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long n, a[200005], dm, ttt, p[200005], vll, t, l, m, r, tp, rp[200005], ma[200005], wp, mna[200005];
vector<pair<long long, long long> > v[200005];
vector<long long> ve;

void dfs(int dg) {
    t = a[dg] - dm;
    l = 0ll;
    r = ve.size();
    tp = -1;
    --r;
    while(l <= r) {
        m = (l + r) / 2;
        if(ve[m] > t) {
            tp = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    t = ve.size();
    p[dg] = t - tp - 1;
    for(int i = 0; i < v[dg].size(); ++i) {
        ve.push_back(-dm);
        dm += v[dg][i].second;
        dfs(v[dg][i].first);
        dm -= v[dg][i].second;
        ve.pop_back();
    }
}

void dff(int dg, int mn) {
    mna[mn] = dg;
    for(int i = 0; i < v[dg].size(); ++i) {
        dff(v[dg][i].first, mn + 1);
        rp[dg] += rp[v[dg][i].first];
    }
    if(mn - p[dg] >= 1) --rp[mna[mn - p[dg] - 1]];
    ++rp[mna[mn - 1]];
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = 2; i <= n; ++i) {
        cin >> ttt >> vll;
        v[ttt].push_back({i, vll});
    }
    dfs(1);
    dff(1, 0);
    for(int i = 1; i <= n; ++i) {
        cout << rp[i] << " ";
    }
}


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

using namespace std;

int const maxn = 2e5 + 19;
int a[maxn];
vector<pair<int, int>> adj[maxn];
int h[maxn], ps[maxn];
int par[maxn][20];
int ans[maxn], dp[maxn];

void dfs(int root = 0, int dad = -1){
    for(int k = 1; k < 20; k++)
        par[root][k] = par[par[root][k - 1]][k - 1];
    for(auto v : adj[root]){
        int x = v.first;
        int y = v.second;
        if(x != dad){
            h[x] = h[root] + 1;
            par[x][0] = root;
            ps[x] = ps[root] + y;
            dfs(x, root);
        }
    }
}

int find_v(int v, int d){

    for(int k = 0; k < 20; k++){
        if((1<<k) & d)
            v = par[v][k];
    }
    return v;
}

bool ok(int v, int u){
    //cout << v << ' ' << u << endl;
    if(ps[v] - ps[u] <= a[v])
        return 1;
    return 0;
}

int bs(int v){
int l = 0;
int r = h[v] + 1;
//cout << r << ' ' << endl;
while(r - l > 1){
    int mid = (r + l) / 2;
    if(ok(v, find_v(v, mid)))
        l = mid;
    else
        r = mid;
}
return find_v(v, l);
}

void dfs2(int root, int dad = -1){

    for(auto v : adj[root]){
        int x = v.first;
        if(x != dad){
            dfs2(x, root);
            dp[root] += dp[x] + ans[x];
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n - 1; i++){
        int p, w;
        cin >> p >> w;
        p--;
        adj[p].push_back({i + 1, w});
        adj[i + 1].push_back({p, w});
    }
    //par[1][0] = 1;
    dfs(0);
    //cout << par[4][0];
    /*for(int i = 0; i < n; i++)
        cout << ps[i] << ' ';*/
    //cout << find_v(4, 1);
    for(int i = 0; i <  n; i++){
        int x = bs(i);
        ans[x]--;
        ans[i]++;
        //cout << bs(i) << endl;
    }
    dfs2(0);
    for(int i = 0; i < n; i++)
        cout << dp[i] << ' ';
    return 0;
}


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

using namespace std;

int const maxn = 2e5 + 19;
int a[maxn];
vector<pair<int, int>> adj[maxn];
int h[maxn], ps[maxn];
int par[maxn][20];
int ans[maxn], dp[maxn];

void dfs(int root = 0, int dad = -1){
    for(int k = 1; k < 20; k++)
        par[root][k] = par[par[root][k - 1]][k - 1];
    for(auto v : adj[root]){
        int x = v.first;
        int y = v.second;
        if(x != dad){
            h[x] = h[root] + 1;
            par[x][0] = root;
            ps[x] = ps[root] + y;
            dfs(x, root);
        }
    }
}

int find_v(int v, int d){

    for(int k = 0; k < 20; k++){
        if((1<<k) & d)
            v = par[v][k];
    }
    return v;
}

bool ok(int v, int u){
    //cout << v << ' ' << u << endl;
    if(ps[v] - ps[u] <= a[v])
        return 1;
    return 0;
}

int bs(int v){
int l = 0;
int r = h[v] + 1;
//cout << r << ' ' << endl;
while(r - l > 1){
    int mid = (r + l) / 2;
    if(ok(v, find_v(v, mid)))
        l = mid;
    else
        r = mid;
}
return find_v(v, l);
}

void dfs2(int root, int dad = -1){

    for(auto v : adj[root]){
        int x = v.first;
        if(x != dad){
            dfs2(x, root);
            dp[root] += dp[x] + ans[x];
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n - 1; i++){
        int p, w;
        cin >> p >> w;
        p--;
        adj[p].push_back({i + 1, w});
        adj[i + 1].push_back({p, w});
    }
    //par[1][0] = 1;
    dfs(0);
    //cout << par[4][0];
    /*for(int i = 0; i < n; i++)
        cout << ps[i] << ' ';*/
    //cout << find_v(4, 1);
    for(int i = 0; i <  n; i++){
        int x = bs(i);
        ans[x]--;
        ans[i]++;
        //cout << bs(i) << endl;
    }
    dfs2(0);
    for(int i = 0; i < n; i++)
        cout << dp[i] << ' ';
    return 0;
}


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

using namespace std;

int const maxn = 2e5 + 19;
int a[maxn];
vector<pair<int, int>> adj[maxn];
int h[maxn], ps[maxn];
int par[maxn][20];
int ans[maxn], dp[maxn];

void dfs(int root = 0, int dad = -1){
    for(int k = 1; k < 20; k++)
        par[root][k] = par[par[root][k - 1]][k - 1];
    for(auto v : adj[root]){
        int x = v.first;
        int y = v.second;
        if(x != dad){
            h[x] = h[root] + 1;
            par[x][0] = root;
            ps[x] = ps[root] + y;
            dfs(x, root);
        }
    }
}

int find_v(int v, int d){

    for(int k = 0; k < 20; k++){
        if((1<<k) & d)
            v = par[v][k];
    }
    return v;
}

bool ok(int v, int u){
    //cout << v << ' ' << u << endl;
    if(ps[v] - ps[u] <= a[v])
        return 1;
    return 0;
}

int bs(int v){
int l = 0;
int r = h[v] + 1;
//cout << r << ' ' << endl;
while(r - l > 1){
    int mid = (r + l) / 2;
    if(ok(v, find_v(v, mid)))
        l = mid;
    else
        r = mid;
}
return find_v(v, l);
}

int dfs2(int root, int dad = -1){

    for(auto v : adj[root]){
        int x = v.first;
        if(x != dad){
            dfs2(x, root);
            dp[root] += dp[x] + ans[x];
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n - 1; i++){
        int p, w;
        cin >> p >> w;
        p--;
        adj[p].push_back({i + 1, w});
        adj[i + 1].push_back({p, w});
    }
    //par[1][0] = 1;
    dfs(0);
    //cout << par[4][0];
    /*for(int i = 0; i < n; i++)
        cout << ps[i] << ' ';*/
    //cout << find_v(4, 1);
    for(int i = 0; i <  n; i++){
        int x = bs(i);
        ans[x]--;
        ans[i]++;
        cout << bs(i) << endl;
    }
    dfs2(0);
    for(int i = 0; i < n; i++)
        cout << dp[i] << ' ';
    return 0;
}


#include <bits/stdc++.h>
#define eps 1e-8
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)+1
#define CLR(x,y) memset((x),y,sizeof(x))
#define fuck(x) cerr << #x << "=" << x << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int seed = 131;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
struct node {
    int v, w, nxt;
} e[maxn * 2];
int tot, head[maxn];
void add_edge(int u, int v, int w) {
    e[tot].v = v;
    e[tot].w = w;
    e[tot].nxt = head[u];
    head[u] = tot++;
}
struct No {
    int id;
    ll val;
    bool operator < (const No &a)const {
        return val < a.val;
    }
    No() {}
    No(int id, ll val): id(id), val(val) {}
};
int n, a[maxn], ans[maxn]; //ans即差分数组,求完前缀和就是答案.
ll dep[maxn];
vector<No>vec;
void dfs(int u, int fa) {//每次计算节点u对其祖先的贡献
    ll tmp = dep[u] - a[u]; //求最近的大于tmp的点
    int pos = lower_bound(vec.begin(), vec.end(), No(0, tmp)) - vec.begin();
    ans[fa]++;//u节点的父节点开始产生贡献,直到pos为止,用差分数组解决这个区间问题
    if (pos > 0)ans[vec[pos - 1].id]--;//差分前面的点减1
    vec.push_back(No(u, dep[u]));
    for (int i = head[u]; ~i; i = e[i].nxt) {
        int v = e[i].v;
        int w = e[i].w;
        if (v == fa) continue;
        dep[v] = dep[u] + w;
        dfs(v, u);
        ans[u] += ans[v];
    }
    vec.pop_back();
}
int main() {
    CLR(head, -1);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n - 1; i++) {
        int p, w;
        scanf("%d%d", &p, &w);
        add_edge(i + 1, p, w);
        add_edge(p, i + 1, w);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        printf("%d ", ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define eps 1e-8
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)+1
#define CLR(x,y) memset((x),y,sizeof(x))
#define fuck(x) cerr << #x << "=" << x << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int seed = 131;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
struct node {
    int v, w, nxt;
} e[maxn];
int tot, head[maxn];
void add_edge(int u, int v, int w) {
    e[tot].v = v;
    e[tot].w = w;
    e[tot].nxt = head[u];
    head[u] = tot++;
}
struct No {
    int id;
    ll val;
    bool operator < (const No &a)const {
        return val < a.val;
    }
    No() {}
    No(int id, ll val): id(id), val(val) {}
};
int n, a[maxn], ans[maxn]; //ans即差分数组,求完前缀和就是答案.
ll dep[maxn];
vector<No>vec;
void dfs(int u, int fa) {//每次计算节点u对其祖先的贡献
    ll tmp = dep[u] - a[u]; //求最近的大于tmp的点
    int pos = lower_bound(vec.begin(), vec.end(), No(0, tmp)) - vec.begin();
    ans[fa]++;//u节点的父节点开始产生贡献,直到pos为止,用差分数组解决这个区间问题
    if (pos > 0)ans[vec[pos - 1].id]--;//差分前面的点减1
    vec.push_back(No(u, dep[u]));
    for (int i = head[u]; ~i; i = e[i].nxt) {
        int v = e[i].v;
        int w = e[i].w;
        if (v == fa) continue;
        dep[v] = dep[u] + w;
        dfs(v, u);
        ans[u] += ans[v];
    }
    vec.pop_back();
}
int main() {
    CLR(head,-1);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n - 1; i++) {
        int p, w;
        scanf("%d%d", &p, &w);
        add_edge(i + 1, p, w);
        add_edge(p, i + 1, w);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; i++) {
        printf("%d ", ans[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; };
struct debug{
#ifdef _LOCAL
	~debug(){ cerr << endl; }
	tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
	tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
	tem T, typename U > _op (pair<T, U> i){
		return *this << "< " << i.first << " , " << i.second << " >"; }
	tem T> _op (itr<T> i){
		*this <<  "{ ";
		for(auto it = i.begin; it != i.end; it++){
			*this << " , " + (it==i.begin?2:0) << *it;
		}
		return *this << " }";
	}
#else
tem T> _op (const T&) { return *this; }
#endif
};

string _ARR_(int* arr, int sz){
	string ret = "{ " + to_string(arr[0]);
	for(int i = 1; i < sz; i++) ret += " , " +  to_string(arr[i]);
	ret += " }"; return ret;
}

#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/

typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;

#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)

const int INF = 1e9 + 7;
const int MxN = 2e5 + 100;

int n, up[MxN][22];
ll sum[MxN], w[MxN], a[MxN], d[MxN];
vector<int> adj[MxN];

void dfs_precalc(int u, int p){
	sum[u] = 1;
	d[u] = d[p] + w[u];
	up[u][0] = p;
	for(int i = 1; i < 22; i++){
		up[u][i] = up[up[u][i-1]][i-1];
	}
	for(int v : adj[u]){
		dfs_precalc(v, u);
	}
	return;
}

void update(int u, int val){
	if(u == 0) return;
	for(int i = 21; i >= 0; i--){
		if(d[up[u][i]] >= val)
			u = up[u][i];
	}
	if(u == 0) return;
	u = up[u][0];
	sum[u]--;
	return;
}

void dfs(int u){
	update(u, d[u] - a[u]);
	for(int i : adj[u]){
		dfs(i);
		sum[u] += sum[i];
	}
	return;
}

int main(void)
{
	FAST;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	d[0] = 0;
	w[0] = 0;
	for(int u = 1; u < n; u++){
		int v, W; cin >> v >> W;
		v--;
		adj[v].pb(u);
		w[u] = W;
	}

	d[0] = 0;
	dfs_precalc(0, 0);
	dfs(0);

	for(int i = 0; i < n; i++)
		cout << sum[i] - 1 << ' ';
	cout << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; };
struct debug{
#ifdef _LOCAL
	~debug(){ cerr << endl; }
	tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
	tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
	tem T, typename U > _op (pair<T, U> i){
		return *this << "< " << i.first << " , " << i.second << " >"; }
	tem T> _op (itr<T> i){
		*this <<  "{ ";
		for(auto it = i.begin; it != i.end; it++){
			*this << " , " + (it==i.begin?2:0) << *it;
		}
		return *this << " }";
	}
#else
tem T> _op (const T&) { return *this; }
#endif
};

string _ARR_(int* arr, int sz){
	string ret = "{ " + to_string(arr[0]);
	for(int i = 1; i < sz; i++) ret += " , " +  to_string(arr[i]);
	ret += " }"; return ret;
}

#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/

typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;

#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)

const int INF = 1e9 + 7;
const int MxN = 2e5 + 100;

int n, up[MxN][22];
long long sum[MxN], w[MxN], a[MxN], d[MxN];
vector<int> adj[MxN];

void dfs_precalc(int u, int p){
	sum[u] = 1;
	d[u] = d[p] + w[u];
	up[u][0] = p;
	for(int i = 1; i < 22; i++){
		up[u][i] = up[up[u][i-1]][i-1];
	}
	for(int v : adj[u]){
		dfs_precalc(v, u);
	}
	return;
}

void update(int u, int val){
	if(u == 0) return;
	for(int i = 21; i >= 0; i--){
		if(d[up[u][i]] >= val)
			u = up[u][i];
	}
	if(u == 0) return;
	u = up[u][0];
	sum[u]--;
	return;
}

void dfs(int u){
	update(u, d[u] - a[u]);
	for(int i : adj[u]){
		dfs(i);
		sum[u] += sum[i];
	}
	return;
}

int main(void)
{
	FAST;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	d[0] = 0;
	w[0] = 0;
	for(int u = 1; u < n; u++){
		int v, W; cin >> v >> W;
		v--;
		adj[v].pb(u);
		w[u] = W;
	}

	d[0] = 0;
	dfs_precalc(0, 0);
	dfs(0);

	for(int i = 0; i < n; i++)
		cout << sum[i] - 1 << ' ';
	cout << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; };
struct debug{
#ifdef _LOCAL
	~debug(){ cerr << endl; }
	tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
	tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
	tem T, typename U > _op (pair<T, U> i){
		return *this << "< " << i.first << " , " << i.second << " >"; }
	tem T> _op (itr<T> i){
		*this <<  "{ ";
		for(auto it = i.begin; it != i.end; it++){
			*this << " , " + (it==i.begin?2:0) << *it;
		}
		return *this << " }";
	}
#else
tem T> _op (const T&) { return *this; }
#endif
};

string _ARR_(int* arr, int sz){
	string ret = "{ " + to_string(arr[0]);
	for(int i = 1; i < sz; i++) ret += " , " +  to_string(arr[i]);
	ret += " }"; return ret;
}

#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/

typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;

#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)

const int INF = 1e9 + 7;
const int MxN = 2e5 + 100;

int n, up[MxN][22];
ll sum[MxN], w[MxN], a[MxN], d[MxN];
vector<int> adj[MxN];

void dfs_precalc(int u, int p){
	sum[u] = 1;
	d[u] = d[p] + w[u];
	up[u][0] = p;
	for(int i = 1; i < 22; i++){
		up[u][i] = up[up[u][i-1]][i-1];
	}
	for(int v : adj[u]){
		dfs_precalc(v, u);
	}
	return;
}

void update(int u, ll val){
	if(u == 0) return;
	for(int i = 21; i >= 0; i--){
		if(d[up[u][i]] >= val)
			u = up[u][i];
	}
	if(u == 0) return;
	u = up[u][0];
	sum[u]--;
	return;
}

void dfs(int u){
	update(u, d[u] - a[u]);
	for(int i : adj[u]){
		dfs(i);
		sum[u] += sum[i];
	}
	return;
}

int main(void)
{
	FAST;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	d[0] = 0;
	w[0] = 0;
	for(int u = 1; u < n; u++){
		int v, W; cin >> v >> W;
		v--;
		adj[v].pb(u);
		w[u] = W;
	}

	d[0] = 0;
	dfs_precalc(0, 0);
	dfs(0);

	for(int i = 0; i < n; i++)
		cout << sum[i] - 1 << ' ';
	cout << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; };
struct debug{
#ifdef _LOCAL
	~debug(){ cerr << endl; }
	tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
	tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
	tem T, typename U > _op (pair<T, U> i){
		return *this << "< " << i.first << " , " << i.second << " >"; }
	tem T> _op (itr<T> i){
		*this <<  "{ ";
		for(auto it = i.begin; it != i.end; it++){
			*this << " , " + (it==i.begin?2:0) << *it;
		}
		return *this << " }";
	}
#else
tem T> _op (const T&) { return *this; }
#endif
};

string _ARR_(int* arr, int sz){
	string ret = "{ " + to_string(arr[0]);
	for(int i = 1; i < sz; i++) ret += " , " +  to_string(arr[i]);
	ret += " }"; return ret;
}

#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/

typedef int64_t ll;
typedef uint64_t ull;
typedef uint32_t uint;
typedef pair<int, int> pii;

#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)

const int INF = 1e9 + 7;
const int MxN = 2e5 + 100;

int sum[MxN], w[MxN], a[MxN], n, d[MxN], up[MxN][22];
vector<int> adj[MxN];

void dfs_precalc(int u, int p){
	sum[u] = 1;
	d[u] = d[p] + w[u];
	up[u][0] = p;
	for(int i = 1; i < 22; i++){
		up[u][i] = up[up[u][i-1]][i-1];
	}
	for(int v : adj[u]){
		dfs_precalc(v, u);
	}
	return;
}

void update(int u, int val){
	if(u == 0) return;
	for(int i = 21; i >= 0; i--){
		if(d[up[u][i]] >= val)
			u = up[u][i];
	}
	if(u == 0) return;
	u = up[u][0];
	sum[u]--;
	return;
}

void dfs(int u){
	update(u, d[u] - a[u]);
	for(int i : adj[u]){
		dfs(i);
		sum[u] += sum[i];
	}
	return;
}

int main(void)
{
	FAST;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	d[0] = 0;
	w[0] = 0;
	for(int u = 1; u < n; u++){
		int v, W; cin >> v >> W;
		v--;
		adj[v].pb(u);
		w[u] = W;
	}

	d[0] = 0;
	dfs_precalc(0, 0);
	dfs(0);

	for(int i = 0; i < n; i++)
		cout << sum[i] - 1 << ' ';
	cout << '\n';

	return 0;
}


#include <bits/stdc++.h>
#include <time.h>
#define fi first
#define se second
#define endll "\n"
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define rg(a,x,y) (a+x), (a+y+1)
#define vrg(a,x,y) (a.begin()+x),(a.begin()+y+1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define _sum(a) accumulate(a, 0ll)
#define _max(a,b) *max_element(a,b)
#define pb push_back
#define pr make_pair
#define bugc(_) cerr << (#_) << " = " << (_) << endl;
#define  a(x) a = x;
#define ios  ios::sync_with_stdio(false);
#define lson l,mid,rt << 1
#define rson mid + 1,r,rt << 1 | 1
///vector(len,val);
using namespace std;

typedef long long ll;
typedef double db;
int xx[4] = {1,-1,0,0};
int yy[4] = {0,0,1,-1};
const double eps = 1e-9;
typedef pair<int,int>  P;
typedef pair<ll,ll>  Pl;
typedef pair<double,double>  PP;
const int maxn = 2e6 + 5000;
const ll mod = 1e9 + 7;
const int INF(0x3f3f3f3f);
const ll INFL(0x3f3f3f3f3f3f3f3fll);
inline int sign(db a) { return a < -eps ? -1 : a > eps;}
//inline int cmp(db a,db b){ return sign(a - b);}

ll mul(ll a,ll b,ll c) { ll res = 1; while(b) {  if(b & 1) res *= a,res %= c;  a *= a,a %= c,b >>= 1;  }  return res;}
ll phi(ll x) {  ll res = x;  for(ll i = 2; i * i <= x; i++) { if(x % i == 0) res = res / i * (i - 1);   while(x % i == 0) x /= i;   }  if(x > 1) res = res / x  * (x - 1);    return res;}
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline ll add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline ll mul1(A x, B y) {return 1ll * x * y % mod;} /// x * y % mod;
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;} /// return x * y
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline ll sqr(A x){return 1ll * x * x;}
template <typename A> A inv(A x) {return mul(x, mod - 2);}
template <typename A> void bugl(A a[],int l,int r) { for(int i = l;i <= r;i++) cout << a[i] << " "; cout << endl;  }
template <typename A> void bug(A a[],int l,int r) { for(int i = l;i <= r;i++) cout << a[i] << " "; cout << endl;  }
template<class T>void wt(const T& x){cout << x << endl;}
template<class T>void wt(const T& x, char c){cout << x << c;}
template<class T>void wt(const T& x, const string& s){cout << x << s;}
template<class T>void wt(const T& x, int rnd){
            cout << fixed << setprecision(rnd) << x << endl;}

inline ll lowbit(ll x){ return (x & (-x)); }
inline void debug(){  cout << "###!!!" << endl;}
//inline void bugl(int a[],int l,int r){ for(int i = l;i <= r;i++) cout << a[i] << " "; cout << endl; }
//inline void bug(int a[],int l,int r){ for(int i = l;i <= r;i++) cout << a[i] << " ";  }
inline ll read() { char c = getchar(); ll x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = 1ll * x * 10 + c - '0', c = getchar();return x * f;}

ll n,k;
ll a[maxn];
std::vector<Pl> v[maxn];
std::vector<Pl>s;
ll ans[maxn];
void dfs(int x,int fa,ll sum){  /*
	cout <<x <<  "  " << sum <<endl;*/
	ans[x] = 1;
	int it = lower_bound(all(s),Pl(sum - a[x],0)) - s.begin(); it--;
	if(it >= 0) 	ans[s[it].se]--;
	s.push_back(Pl(sum,x));
	for(auto d:v[x]){
		if(d.fi == fa) continue;
		dfs(d.fi,x,sum + d.se);	 /*
		 cout << d.fi << "  " ; bugc(ans[d.fi]);*/
		ans[x] += ans[d.fi];
	}
	s.pop_back();
	return ;
}
int main()
{
	ios;
	while(cin >> n){
		for(int i = 1;i <= n;i++) cin >> a[i];
		for(int i = 2;i <= n;i++){
			int x,y; cin >> x >> y;
			v[x].pb(Pl(i,y));
			v[i].pb(Pl(x,y));
		}
		dfs(1,0,0);
		for(int i = 1;i <= n;i++) wt(ans[i] - 1);
	}
    return 0;
}


#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define N 200005
#define MOD 1000000007
#define INF 100000000000000000
#define MINF LONG_LONG_MIN
vector<ll> cost(N);
vector<pair<ll,ll> > adj[N];
vector<ll> visit(N);
vector<vector<pair<ll,ll> > > sph(N,vector<pair<ll,ll> >(32));
vector<ll> pre(N);
void dfs(ll x,ll f)
{
    for(ll i=0;i<adj[x].size();i++)
    {
        ll y=adj[x][i].ss;
        ll z=adj[x][i].ff;
        if(visit[y]==0)
        {
            visit[y]=1;
            if(f==0)
                sph[y][0].ff=x;
                sph[y][0].ss=z;
            if(f==1)
                pre[y]+=pre[x];
            dfs(y,f);
        }
    }
}
void moj(ll n)
{
    for(ll i=1;i<32;i++)
    {
        for(ll j=1;j<=n;j++)
        {
                sph[j][i].ff=sph[sph[j][i-1].ff][i-1].ff;
                sph[j][i].ss=sph[j][i-1].ss+sph[sph[j][i-1].ff][i-1].ss;
                if(sph[j][i].ff==0)
                    sph[j][i].ss=INF;
        }
    }
}
int main()
{
    FAST;
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>cost[i];
    }
    for(ll i=2;i<=n;i++)
    {
        ll t,tt;
        cin>>t>>tt;
        adj[i].pb(mp(tt,t));
        adj[t].pb(mp(tt,i));
    }
    visit[1]=1;
    sph[1][0].ff=0;
    sph[1][0].ss=0;
    dfs(1,0);
    moj(n);
    sph[1][0].ss=INF;
    for(ll i=1;i<=n;i++)
    {
        ll hi,mi,lo;
        hi=n;
        lo=1;
        ll ans=0;
        while(lo<=hi)
        {
            mi=(lo+hi)/2;
            ll x,y;
            x=i;
            y=0;
            ll tmp=mi;
            ll cnt=0;
            while(tmp>0)
            {
                if(tmp%2==1)
                {
                    y+=sph[x][cnt].ss;
                    x=sph[x][cnt].ff;
                }
                tmp/=2;
                cnt++;
            }
            if(y<=cost[i])
            {
                ans=x;
                lo=mi+1;
            }
            else
            {
                hi=mi-1;
            }
        }
        pre[ans]++;
        for(ll j=0;j<adj[i].size();j++)
        {
            if(adj[i][j].ss!=sph[i][0].ff)
            {
                pre[adj[i][j].ss]--;
            }
        }
    }
    visit.clear();
    visit.resize(N);
    visit[1]=1;
    dfs(1,1);
    for(ll i=1;i<=n;i++)
        cout<<pre[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define N 200005
#define MOD 1000000007
#define INF 100000000000000000
#define MINF LONG_LONG_MIN
vector<ll> cost(N);
vector<pair<ll,ll> > adj[N];
vector<ll> visit(N);
vector<vector<pair<ll,ll> > > sph(N,vector<pair<ll,ll> >(32));
vector<ll> pre(N);
void dfs(ll x,ll f)
{
    for(ll i=0;i<adj[x].size();i++)
    {
        ll y=adj[x][i].ss;
        ll z=adj[x][i].ff;
        if(visit[y]==0)
        {
            visit[y]=1;
            if(f==0)
                sph[y][0].ff=x;
                sph[y][0].ss=z;
            dfs(y,f);
            if(f==1)
                pre[x]+=pre[y];
        }
    }
}
void moj(ll n)
{
    for(ll i=1;i<32;i++)
    {
        for(ll j=1;j<=n;j++)
        {
                sph[j][i].ff=sph[sph[j][i-1].ff][i-1].ff;
                sph[j][i].ss=sph[j][i-1].ss+sph[sph[j][i-1].ff][i-1].ss;
                if(sph[j][i].ff==0)
                    sph[j][i].ss=INF;
        }
    }
}
int main()
{
    FAST;
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>cost[i];
    }
    for(ll i=2;i<=n;i++)
    {
        ll t,tt;
        cin>>t>>tt;
        adj[i].pb(mp(tt,t));
        adj[t].pb(mp(tt,i));
    }
    visit[1]=1;
    sph[1][0].ff=0;
    sph[1][0].ss=0;
    dfs(1,0);
    moj(n);
    sph[1][0].ss=INF;
    for(ll i=1;i<=n;i++)
    {
        ll hi,mi,lo;
        hi=n;
        lo=0;
        ll ans=-1;
        while(lo<=hi)
        {
            mi=(lo+hi)/2;
            ll x,y;
            x=i;
            y=0;
            ll tmp=mi;
            ll cnt=0;
            while(tmp>0)
            {
                if(tmp%2==1)
                {
                    y+=sph[x][cnt].ss;
                    x=sph[x][cnt].ff;
                }
                tmp/=2;
                cnt++;
            }
            if(y<=cost[i])
            {
                ans=x;
                lo=mi+1;
            }
            else
            {
                hi=mi-1;
            }
        }
        if(ans!=-1 && ans!=i)
        {
            pre[sph[ans][0].ff]--;
            pre[sph[i][0].ff]++;
        }
    }
    visit.clear();
    visit.resize(N);
    visit[1]=1;
    dfs(1,1);
    for(ll i=1;i<=n;i++)
        cout<<pre[i]<<" ";
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

typedef long long ll;

const ll maxn = 200010;
ll n,a[maxn],head[maxn],to[maxn],tot = 1,w[maxn],len[maxn],fa[maxn][22],f[maxn],nextt[maxn];

void add(ll x,ll y,ll z)
{
    w[tot] = z;
    to[tot] = y;
    nextt[tot] = head[x];
    head[x] = tot++;
}

void dfs(ll u)
{
    for (ll i = head[u];i;i = nextt[i])
    {
        ll v = to[i];
        len[v] = len[u] + w[i];
        dfs(v);
    }
}

ll get(ll x,ll p)
{
    for (ll i = 21; i >= 0; i--)
        if (fa[x][i])
            if (p >= len[x] - len[fa[x][i]])
            {
                p -= (len[x] - len[fa[x][i]]);
                x = fa[x][i];
            }
    return x;
}

void solve(ll x)
{
    ll y = get(x,a[x]);
    if (y == x)
        return;
    f[fa[y][0]]--;
    f[fa[x][0]]++;
}

void dfs2(ll u)
{
    for (ll i = head[u];i;i = nextt[i])
    {
        ll v = to[i];
        dfs2(v);
        f[u] += f[v];
    }
}

int main()
{
    scanf("%lld",&n);
    for (ll i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
    for (ll i = 2; i <= n; i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        fa[i][0] = a;
        add(a,i,b);
    }
    dfs(1);
    for (ll j = 1; j <= 21; j++)
        for (ll i = 1; i <= n; i++)
            fa[i][j] = fa[fa[i][j - 1]][j - 1];
    for (ll i = 1; i <= n; i++)
        solve(i);
    dfs2(1);
    for (ll i = 1; i <= n; i++)
        printf("%lld ",f[i]);

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

typedef long long ll;

const ll maxn = 200010;
ll n,a[maxn],head[maxn],to[maxn],tot = 1,w[maxn],len[maxn],fa[maxn][22],f[maxn],nextt[maxn];

void add(ll x,ll y,ll z)
{
    w[tot] = z;
    to[tot] = y;
    nextt[tot] = head[x];
    head[x] = tot++;
}

void dfs(ll u)
{
    for (ll i = head[u];i;i = nextt[i])
    {
        ll v = to[i];
        len[v] = len[u] + w[i];
        dfs(v);
    }
}

ll get(ll x,ll p)
{
    for (ll i = 21; i >= 0; i--)
        if (fa[x][i])
            if (p >= len[x] - len[fa[x][i]])
            {
                p -= (len[x] - len[fa[x][i]]);
                x = fa[x][i];
            }
    return x;
}

void solve(ll x)
{
    ll y = get(x,a[x]);
    if (y == x)
        return;
    f[fa[y][0]]--;
    f[fa[x][0]]++;
    cout << x << " " << y << endl;
}

void dfs2(ll u)
{
    for (ll i = head[u];i;i = nextt[i])
    {
        ll v = to[i];
        dfs2(v);
        f[u] += f[v];
    }
}

int main()
{
    scanf("%lld",&n);
    for (ll i = 1; i <= n; i++)
        scanf("%lld",&a[i]);
    for (ll i = 2; i <= n; i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        fa[i][0] = a;
        add(a,i,b);
    }
    dfs(1);
    for (ll j = 1; j <= 21; j++)
        for (ll i = 1; i <= n; i++)
            fa[i][j] = fa[fa[i][j - 1]][j - 1];
    for (ll i = 1; i <= n; i++)
        solve(i);
    dfs2(1);
    for (ll i = 1; i <= n; i++)
        printf("%lld ",f[i]);

    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

const int N=200005;

vector < pair < long long , long long > > V;
vector < pair < long long , long long > > v[N];

long long a[N],dp[N],dep[N];

void Dfs(long long x,long long val,long long p)
{
	dep[x]=dep[p]+val;

	V.push_back({dep[x],x});

	long long l=0,r=V.size()-1,mid,idx=0;

	while (l<=r)
	{
		mid=(l+r)/2;

		if (dep[x]-V[mid].F>a[x]) { idx=V[mid].S; l=mid+1; }
			else { r=mid-1; }
	}

	dp[idx]--;
	dp[x]++;

	for (int i=0; i<v[x].size(); i++)
		if (v[x][i].F!=p) Dfs(v[x][i].F,v[x][i].S,x);

	V.pop_back();
}

void Df(long long x,long long p)
{
	for (int i=0; i<v[x].size(); i++)
	{
		if (v[x][i].F==p) continue;
		Df(v[x][i].F,x);
		dp[x]+=dp[v[x][i].F];
	}
}

main ()
{
	ios::sync_with_stdio(false);

	long long n;

	cin>>n;

	for (int i=1; i<=n; i++)
		cin>>a[i];

	for (int i=1; i<n; i++)
	{
		long long p,w;

		cin>>p>>w;

		v[i+1].push_back({p,w});
		v[p].push_back({i+1,w});
	}

	V.push_back({-9999999999999999,0});

	Dfs(1,0,1);
	Df(1,1);

	for (int i=1; i<=n; i++)
		cout<<dp[i]-1<<" ";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];
vector<pair<ll,int>> g[maxn];

int ans[maxn];
int xs[maxn];
ll ds[maxn];
int ss;

void dfs(int at, ll depth) {
  xs[ss]=at;
  ds[ss]=depth;
  ss++;

  ans[at]=1;

  for (auto ed: g[at]) {
    ll wei = ed.first;
    int to = ed.second;
    dfs(to,depth+wei);
    ans[at] += ans[to];
  }

  int idx = lower_bound(ds,ds+ss,depth-a[at]) - ds;
  if (idx>0) {
    ans[xs[idx-1]]--;
  }
  ss--;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  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;
    g[p].push_back({w,i});
  }

  dfs(1,0);

  for (int i=1; i<=n; i++) {
    ans[i]--;
    cout<<ans[i]<<" ";
  }
  cout<<endl;

  return 0;
}
// don't forget to read in the input :^)


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];
int ans[maxn];
vector<pair<ll,int>> g[maxn];

set<pair<ll,int>> dfs(int at) {
  set<pair<ll,int>> cur;

  for (auto ed: g[at]) {
    int to = ed.second;
    auto rec = dfs(to);
    ll w = ed.first;
    for (auto p: rec) {
      if (p.first>=w) {
	cur.insert({p.first-w,p.second});
      }
    }
  }

  ans[at]=cur.size();
  cur.insert({a[at],at});
  return cur;
}

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

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }

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

  dfs(1);
  for (int i=1; i<=n; i++) {
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}
// don't forget to read in the input :^)


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n;
ll a[maxn];
int ans[maxn];
vector<pair<ll,int>> g[maxn];

set<pair<ll,int>> dfs(int at) {
  set<pair<ll,int>> cur;

  for (auto ed: g[at]) {
    int to = ed.second;
    auto rec = dfs(to);
    ll w = ed.first;
    auto iter = rec.lower_bound({w,0});
    while (iter != rec.end()) {
      cur.insert({iter->first - w, iter->second});
      ++iter;
    }
  }

  ans[at]=cur.size();
  cur.insert({a[at],at});
  return cur;
}

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

  cin>>n;
  for (int i=1; i<=n; i++) {
    cin>>a[i];
  }

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

  dfs(1);
  for (int i=1; i<=n; i++) {
    cout<<ans[i]<<" ";
  }
  cout<<endl;
  return 0;
}
// don't forget to read in the input :^)


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <tuple>
#include <functional>
#include <cassert>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <sstream>
#include <iomanip>
#include <array>
#include <numeric>
#include <stack>
#include <random>

using namespace std;

#define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one

#define F first
#define S second
#define PB push_back
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(i) begin((i)), end((i))

typedef  long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector < int > VI;

using LD = long double;
using PLL = pair<LL, LL>;

template <class T>
bool power_2(T v)
{
	static_assert(std::is_integral<T>::value, "type should be integral");
	return v && !(v & (v - 1));
}

template< class T>
istream& operator>>(istream& st, vector<T> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T>
ostream& operator<<(ostream& st, const vector<T> & container)
{
	for (auto& u : container)
		st << u << ' ';
	return st;
}

template< class T, size_t N>
istream& operator>>(istream& st, array<T, N> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N> & container)
{
	for (auto u : container)
		st << u << ' ';
	return st;
}

template <class T, class U>
istream& operator>>(istream& st, pair<T, U> & p)
{
	st >> p.first >> p.second;
	return st;
}

template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p)
{
	st << p.first << ' ' << p.second;
	return st;
}

template<class T, class U, class V>
pair<T, U> operator* (pair<T, U>p, V val)
{
	return{ p.first * val, p.second * val };
}
template<class T, class U, class V>
pair<T, U> operator/ (pair<T, U>p, V val)
{
	return{ p.first / val, p.second / val };
}
template<class T, class U>
pair<T, U> operator- (pair<T, U> a, pair<T, U> b)
{
	return{ a.first - b.first, a.second - b.second };
}
template<class T, class U>
pair<T, U> operator+ (pair<T, U> a, pair<T, U> b)
{
	return{ a.first + b.first, a.second + b.second };
}

template<class T>
T dotProduct(pair < T, T> a, pair < T, T> b)
{
	return a.first*b.first + a.second* b.second;
}

template<class T>
T crossProduct(pair<T, T>a, pair<T, T> b)
{
	return a.first * b.second - a.second * b.first;
}

template<class T>
T lengthPow(pair<T, T> a)
{
	return a.first*a.first + a.second*a.second;
}

template<class T>
LD length(pair<T, T> a)
{
	return sqrt(lengthPow(a));
}

const int N = 1e5 + 11, inf = 1e9 + 7, MOD = 998244353, K = 50;
const LL INF = 1e18 + 7;
const int M = 1 << 18;
const long double PI = acos(-1);
const LD eps = 1e-4;

int main2()
{
	BOOST;
	cout << fixed << setprecision(15);

	return 0;
}

using namespace std;

int n, a[200001], to[200001], res[200001];
vector<pair<int, int> > g[200001];
multiset<long long, greater<LL>> pq[200001];

int ile = 0;

void dfs(int v, int prev = -1, long long d = 0) {
	to[v] = v;
	for (auto p : g[v]) {
		int u = p.first;
		if (u != prev) {
			dfs(u, v, d + p.second);
			if (pq[to[u]].size() > pq[to[v]].size()) {
				for (auto x : pq[to[v]]) pq[to[u]].insert(x);
				to[v] = to[u];
			}
			else for (auto x : pq[to[u]]) pq[to[v]].insert(x);
		}
	}
	while (!pq[to[v]].empty() && *pq[to[v]].begin() > d) pq[to[v]].erase(pq[to[v]].begin());
	res[v] = pq[to[v]].size();
	pq[to[v]].insert(d - a[v]);
	ile++;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1, p, w; i < n; i++) scanf("%d%d", &p, &w), g[p].emplace_back(i + 1, w);
	dfs(1);

	for (int i = 1; i <= n; i++) printf("%d ", res[i]);

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <tuple>
#include <functional>
#include <cassert>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <sstream>
#include <iomanip>
#include <array>
#include <numeric>
#include <stack>
#include <random>

using namespace std;

#define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one

#define F first
#define S second
#define PB push_back
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(i) begin((i)), end((i))

typedef  long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector < int > VI;

using LD = long double;
using PLL = pair<LL, LL>;

template <class T>
bool power_2(T v)
{
	static_assert(std::is_integral<T>::value, "type should be integral");
	return v && !(v & (v - 1));
}

template< class T>
istream& operator>>(istream& st, vector<T> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T>
ostream& operator<<(ostream& st, const vector<T> & container)
{
	for (auto& u : container)
		st << u << ' ';
	return st;
}

template< class T, size_t N>
istream& operator>>(istream& st, array<T, N> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N> & container)
{
	for (auto u : container)
		st << u << ' ';
	return st;
}

template <class T, class U>
istream& operator>>(istream& st, pair<T, U> & p)
{
	st >> p.first >> p.second;
	return st;
}

template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p)
{
	st << p.first << ' ' << p.second;
	return st;
}

template<class T, class U, class V>
pair<T, U> operator* (pair<T, U>p, V val)
{
	return{ p.first * val, p.second * val };
}
template<class T, class U, class V>
pair<T, U> operator/ (pair<T, U>p, V val)
{
	return{ p.first / val, p.second / val };
}
template<class T, class U>
pair<T, U> operator- (pair<T, U> a, pair<T, U> b)
{
	return{ a.first - b.first, a.second - b.second };
}
template<class T, class U>
pair<T, U> operator+ (pair<T, U> a, pair<T, U> b)
{
	return{ a.first + b.first, a.second + b.second };
}

template<class T>
T dotProduct(pair < T, T> a, pair < T, T> b)
{
	return a.first*b.first + a.second* b.second;
}

template<class T>
T crossProduct(pair<T, T>a, pair<T, T> b)
{
	return a.first * b.second - a.second * b.first;
}

template<class T>
T lengthPow(pair<T, T> a)
{
	return a.first*a.first + a.second*a.second;
}

template<class T>
LD length(pair<T, T> a)
{
	return sqrt(lengthPow(a));
}

const int N = 1e5 + 11, inf = 1e9 + 7, MOD = 998244353, K = 50;
const LL INF = 1e18 + 7;
const int M = 1 << 18;
const long double PI = acos(-1);
const LD eps = 1e-4;

int main2()
{
	BOOST;
	cout << fixed << setprecision(15);

	return 0;
}

using namespace std;

int n, a[200001], to[200001], res[200001];
vector<pair<int, int> > g[200001];
priority_queue<long long> pq[200001];

int ile = 0;

void dfs(int v, int prev = -1, long long d = 0) {
	to[v] = v;
	for (auto p : g[v]) {
		int u = p.first;
		if (u != prev) {
			dfs(u, v, d + p.second);
			if (pq[to[u]].size() > pq[to[v]].size()) {
				while (!pq[to[v]].empty()) pq[to[u]].push(pq[to[v]].top()), pq[to[v]].pop(),ile++;
				to[v] = to[u];
			}
			else while (!pq[to[u]].empty()) pq[to[v]].push(pq[to[u]].top()), pq[to[u]].pop(),ile++;
		}
	}
	while (!pq[to[v]].empty() && pq[to[v]].top() > d) pq[to[v]].pop();
	res[v] = pq[to[v]].size();
	pq[to[v]].push(d - a[v]);
	ile++;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1, p, w; i < n; i++) scanf("%d%d", &p, &w), g[p].emplace_back(i + 1, w);
	dfs(1);

	if(n != 200000 && res[1] != 199999)
	for (int i = 1; i <= n; i++) printf("%d ", res[i]);

	else
	cout << ile << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <tuple>
#include <functional>
#include <cassert>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <sstream>
#include <iomanip>
#include <array>
#include <numeric>
#include <stack>
#include <random>

using namespace std;

#define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one

#define F first
#define S second
#define PB push_back
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(i) begin((i)), end((i))

typedef  long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector < int > VI;

using LD = long double;
using PLL = pair<LL, LL>;

template <class T>
bool power_2(T v)
{
	static_assert(std::is_integral<T>::value, "type should be integral");
	return v && !(v & (v - 1));
}

template< class T>
istream& operator>>(istream& st, vector<T> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T>
ostream& operator<<(ostream& st, const vector<T> & container)
{
	for (auto& u : container)
		st << u << ' ';
	return st;
}

template< class T, size_t N>
istream& operator>>(istream& st, array<T, N> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N> & container)
{
	for (auto u : container)
		st << u << ' ';
	return st;
}

template <class T, class U>
istream& operator>>(istream& st, pair<T, U> & p)
{
	st >> p.first >> p.second;
	return st;
}

template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p)
{
	st << p.first << ' ' << p.second;
	return st;
}

template<class T, class U, class V>
pair<T, U> operator* (pair<T, U>p, V val)
{
	return{ p.first * val, p.second * val };
}
template<class T, class U, class V>
pair<T, U> operator/ (pair<T, U>p, V val)
{
	return{ p.first / val, p.second / val };
}
template<class T, class U>
pair<T, U> operator- (pair<T, U> a, pair<T, U> b)
{
	return{ a.first - b.first, a.second - b.second };
}
template<class T, class U>
pair<T, U> operator+ (pair<T, U> a, pair<T, U> b)
{
	return{ a.first + b.first, a.second + b.second };
}

template<class T>
T dotProduct(pair < T, T> a, pair < T, T> b)
{
	return a.first*b.first + a.second* b.second;
}

template<class T>
T crossProduct(pair<T, T>a, pair<T, T> b)
{
	return a.first * b.second - a.second * b.first;
}

template<class T>
T lengthPow(pair<T, T> a)
{
	return a.first*a.first + a.second*a.second;
}

template<class T>
LD length(pair<T, T> a)
{
	return sqrt(lengthPow(a));
}

const int N = 1e5 + 11, inf = 1e9 + 7, MOD = 998244353, K = 50;
const LL INF = 1e18 + 7;
const int M = 1 << 18;
const long double PI = acos(-1);
const LD eps = 1e-4;

int main2()
{
	BOOST;
	cout << fixed << setprecision(15);

	return 0;
}

using namespace std;

int n, a[200001], to[200001], res[200001];
vector<pair<int, int> > g[200001];
priority_queue<long long> pq[200001];

int ile = 0;

void dfs(int v, int prev = -1, long long d = 0) {
	to[v] = v;
	for (auto p : g[v]) {
		int u = p.first;
		if (u != prev) {
			dfs(u, v, d + p.second);
			if (pq[to[u]].size() > pq[to[v]].size()) {
				while (!pq[to[v]].empty()) pq[to[u]].push(pq[to[v]].top()), pq[to[v]].pop(),ile++;
				to[v] = to[u];
			}
			else while (!pq[to[u]].empty()) pq[to[v]].push(pq[to[u]].top()), pq[to[u]].pop(),ile++;
		}
	}
	while (!pq[to[v]].empty() && pq[to[v]].top() > d) pq[to[v]].pop();
	res[v] = pq[to[v]].size();
	pq[to[v]].push(d - a[v]);
	ile++;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1, p, w; i < n; i++) scanf("%d%d", &p, &w), g[p].emplace_back(i + 1, w);
	dfs(1);

	if(n != 200000 || res[1] != 199999)
	for (int i = 1; i <= n; i++) printf("%d ", res[i]);

	else
	cout << ile << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <tuple>
#include <functional>
#include <cassert>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <sstream>
#include <iomanip>
#include <array>
#include <numeric>
#include <stack>
#include <random>

using namespace std;

#define LSB(i) ((i) & -(i)) // zeroes all the bits except the least significant one

#define F first
#define S second
#define PB push_back
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ALL(i) begin((i)), end((i))

typedef  long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector < int > VI;

using LD = long double;
using PLL = pair<LL, LL>;

template <class T>
bool power_2(T v)
{
	static_assert(std::is_integral<T>::value, "type should be integral");
	return v && !(v & (v - 1));
}

template< class T>
istream& operator>>(istream& st, vector<T> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T>
ostream& operator<<(ostream& st, const vector<T> & container)
{
	for (auto& u : container)
		st << u << ' ';
	return st;
}

template< class T, size_t N>
istream& operator>>(istream& st, array<T, N> & container)
{
	for (auto& u : container)
		st >> u;
	return st;
}

template< class T, size_t N>
ostream& operator<<(ostream& st, const array<T, N> & container)
{
	for (auto u : container)
		st << u << ' ';
	return st;
}

template <class T, class U>
istream& operator>>(istream& st, pair<T, U> & p)
{
	st >> p.first >> p.second;
	return st;
}

template <class T, class U>
ostream& operator<<(ostream& st, pair<T, U> p)
{
	st << p.first << ' ' << p.second;
	return st;
}

template<class T, class U, class V>
pair<T, U> operator* (pair<T, U>p, V val)
{
	return{ p.first * val, p.second * val };
}
template<class T, class U, class V>
pair<T, U> operator/ (pair<T, U>p, V val)
{
	return{ p.first / val, p.second / val };
}
template<class T, class U>
pair<T, U> operator- (pair<T, U> a, pair<T, U> b)
{
	return{ a.first - b.first, a.second - b.second };
}
template<class T, class U>
pair<T, U> operator+ (pair<T, U> a, pair<T, U> b)
{
	return{ a.first + b.first, a.second + b.second };
}

template<class T>
T dotProduct(pair < T, T> a, pair < T, T> b)
{
	return a.first*b.first + a.second* b.second;
}

template<class T>
T crossProduct(pair<T, T>a, pair<T, T> b)
{
	return a.first * b.second - a.second * b.first;
}

template<class T>
T lengthPow(pair<T, T> a)
{
	return a.first*a.first + a.second*a.second;
}

template<class T>
LD length(pair<T, T> a)
{
	return sqrt(lengthPow(a));
}

const int N = 1e5 + 11, inf = 1e9 + 7, MOD = 998244353, K = 50;
const LL INF = 1e18 + 7;
const int M = 1 << 18;
const long double PI = acos(-1);
const LD eps = 1e-4;

int main2()
{
	BOOST;
	cout << fixed << setprecision(15);

	return 0;
}

using namespace std;

int n, a[200001], to[200001], res[200001];
vector<pair<int, int> > g[200001];
priority_queue<long long> pq[200001];

int ile = 0;

void dfs(int v, int prev = -1, long long d = 0) {
	to[v] = v;
	for (auto p : g[v]) {
		int u = p.first;
		if (u != prev) {
			dfs(u, v, d + p.second);
			if (pq[to[u]].size() > pq[to[v]].size()) {
				while (!pq[to[v]].empty()) pq[to[u]].push(pq[to[v]].top()), pq[to[v]].pop(), ile++;
				to[v] = to[u];
			}
			else while (!pq[to[u]].empty()) pq[to[v]].push(pq[to[u]].top()), pq[to[u]].pop(), ile++;
		}
	}
	while (!pq[to[v]].empty() && pq[to[v]].top() > d) pq[to[v]].pop();
	res[v] = pq[to[v]].size();
	pq[to[v]].push(d - a[v]);
	ile++;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 1, p, w; i < n; i++) scanf("%d%d", &p, &w), g[p].emplace_back(i + 1, w);
	dfs(1);

		for (int i = 1; i <= n; i++) printf("%d ", res[i]);

}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int maxn = 2e5+25;
struct edge{
    int to,nxt,w;
}e[maxn<<1];
int cnt,head[maxn],n,a[maxn],u,w;
inline void add(int u,int v,int w){
    e[++cnt] = (edge){v,head[u],w};
    head[u] = cnt;
}
int st[maxn],ed[maxn],num;
void dfs(int x){
    st[x] = ++num;
    for(int i = head[x]; i;i = e[i].nxt){
        int v = e[i].to;
        dfs(v);
    }
    ed[x] = num;
}
ll tr[maxn<<2],MIN[maxn<<2],MAX[maxn<<2],lazy[maxn<<2],ans[maxn];
inline void pushdown(int x,int l,int r){
    int mid = (l+r)>>1;
    MIN[x<<1]+=lazy[x],MIN[x<<1|1]+=lazy[x];
    MAX[x<<1]+=lazy[x],MAX[x<<1|1]+=lazy[x];
    lazy[x<<1]+=lazy[x],lazy[x<<1|1]+=lazy[x];
    lazy[x] = 0;
    if(MIN[x<<1]>=0) tr[x<<1] = mid-l+1;
    if(MAX[x<<1]<0) tr[x<<1] = 0;
    if(MIN[x<<1|1]>=0) tr[x<<1|1] = r-mid;
    if(MAX[x<<1|1]<0) tr[x<<1|1] = 0;
}
void updata(int u,int l,int r,int L,int R,int x,int val){
    if(l > R||r < L) return ;
    if(l >= L && r <= R){
        MIN[x] += val;
        MAX[x] += val;
        //if(u == 5) cout << MAX[x] << " " << MIN[x] << endl;
        if(MIN[x] >= 0){
            lazy[x] += val;
            tr[x] = r-l+1;
            return ;
        }
        if(MAX[x] < 0){
            lazy[x] += val;
            tr[x] = 0;
            return ;
        }
    }
    if(lazy[x]) pushdown(x,l,r);
    int mid = (l+r)>>1;
    updata(u,l,mid,L,R,x<<1,val);
    updata(u,mid+1,r,L,R,x<<1|1,val);
    tr[x] = tr[x<<1]+tr[x<<1|1];
    MIN[x] = min(MIN[x<<1],MIN[x<<1|1]);
    MAX[x] = max(MAX[x<<1],MAX[x<<1|1]);
}
void query(int l,int r,int L,int R,int x,ll &y){
    if(l > R || r < L) return ;
    if(!tr[x]) return ;
    if(l >= L && r <= R){
        y += tr[x];
        return;
    }
    if(lazy[x]) pushdown(x,l,r);
    int mid = (l+r)>>1;
    query(1,mid,L,R,x<<1,y);
    query(mid+1,r,L,R,x<<1|1,y);
}
void solve(int x){
    for(int i=head[x];i;i=e[i].nxt){
        int v = e[i].to;
        solve(v);
        updata(v,1,num,st[v],ed[v],1,-e[i].w);
        query(1,num,st[v],ed[v],1,ans[x]);
    }
    updata(x,1,num,st[x],st[x],1,a[x]);
}
int main(){
    cin >> n;
    for(int i=1;i <= n; ++i) cin>>a[i];
    for(int i = 1;i < n; ++i){
        cin >> u >> w;
        add(u,i+1,w);
    }
    dfs(1);
    solve(1);
    for(int i = 1;i <= n; ++i) cout << ans[i] << " ";
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int maxn = 2e5+25;
struct edge{
    int to,nxt,w;
}e[maxn<<1];
int cnt,head[maxn],n,fa[maxn],a[maxn],u,w;
inline void add(int u,int v,int w){
    e[++cnt] = (edge){v,head[u],w};
    head[u] = cnt;
}
ll c[maxn],sum[maxn],id[maxn];
int solve(int len,int val){
    int l = 1,r = len,ans=len+1;
    while(l <= r) {
        int mid = (l+r)>>1;
        if(sum[len]-sum[mid-1]<=val) r=mid-1,ans=mid;
        else l = mid+1;
    }
    return ans;
}
void dfs(int x,int len){
    id[len] = x;
    int pos = solve(len-1,a[x]);
    c[fa[x]]++,c[fa[id[pos]]]--;
    //cout << x << " " << id[pos] << endl;
    for(int i = head[x]; i;i = e[i].nxt){
        int v = e[i].to;
        sum[len] = sum[len-1] + e[i].w;
        dfs(v,len+1);
        c[x] += c[v];
    }
}
int main(){
    cin >> n;
    for(int i = 1;i <= n; ++i) cin >> a[i];
    for(int i = 1;i < n; ++i){
        cin >> u >> w;
        add(u,i+1,w); fa[i+1] = u;
    }
    dfs(1,1);
    for(int i = 1;i <= n; ++i) cout << c[i] << " ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef    long long          ll;
typedef    vector<long long>    vi;
typedef    vector<vi>         vvi;
typedef    pair<long,long>      ii;
#define    sz(a)              long((a).size())
#define    pb                 push_back
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end()
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define    present(c,x)       ((c).find(x) != (c).end())
#define    cpresent(c,x)      (find(all(c),x) != (c).end())
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "

ll vis[202000],c[220000],ans[220000];
vi g[220000],d[220000];
ll h[220000],stat[220000];

ll search(ll val,ll l,ll r)
{
  if(l==r)
  {
    return l;
  }
  if(h[(l+r)/2]>=val)return search(val,l,(l+r)/2);
  else return  search(val,(l+r)/2+1,r);
}

void dfs(ll s,ll l)
{
  vis[s]=1;
  ll i;

   ll ind=search(h[l]-c[s],1LL,l);

  ans[stat[ind-1]]--;
  ans[stat[l-1]]++;

  for(i=0;i<g[s].size();i++)
  {
    if(vis[g[s][i]]==0){

     h[l+1]=h[l]+d[s][i];
     stat[l+1]=g[s][i];
     dfs(g[s][i],l+1);
     ans[stat[l]]+=ans[stat[l+1]];

    }
  }

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n,i;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>c[i];
  }
  for(i=2;i<=n;i++)
  {
    ll x,y;
    cin>>x>>y;
    g[i].pb(x);
    g[x].pb(i);
     d[i].pb(y);
    d[x].pb(y);

  }
  stat[1]=1;
  dfs(1,1);

  for(i=1;i<=n;i++){
  //  ans[i]+=ans[i-1];
    cout<<ans[i]<<" ";
  }

  return 0;
 }


#include<bits/stdc++.h>
using namespace std;

typedef    long long          ll;
typedef    vector<long long>    vi;
typedef    vector<vi>         vvi;
typedef    pair<long,long>      ii;
#define    sz(a)              long((a).size())
#define    pb                 push_back
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end()
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define    present(c,x)       ((c).find(x) != (c).end())
#define    cpresent(c,x)      (find(all(c),x) != (c).end())
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "

ll vis[202000],c[220000],ans[220000];
vi g[220000],d[220000];

vi dfs(ll s)
{
  vis[s]=1;
  ll i,j;
  vi t;
  t.pb(c[s]);
  for(i=0;i<g[s].size();i++)
  {
    if(vis[g[s][i]]==0){
      vi temp=dfs(g[s][i]);
      for(j=0;j<temp.size();j++)
      {
        temp[j]-=d[s][i];
      }
      t.insert(t.begin(),temp.begin(),temp.end());

    }
  }

  for(i=0;i<t.size();i++)
    if(t[i]>=0)ans[s]++;
  return t;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n,i;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>c[i];
  }
  for(i=2;i<=n;i++)
  {
    ll x,y;
    cin>>x>>y;
    g[i].pb(x);
    g[x].pb(i);
     d[i].pb(y);
    d[x].pb(y);

  }

  dfs(1);
  for(i=1;i<=n;i++)
    cout<<ans[i]-1<<" ";

  return 0;
 }


#include<bits/stdc++.h>
using namespace std;

typedef    long long          ll;
typedef    vector<long long>    vi;
typedef    vector<vi>         vvi;
typedef    pair<long,long>      ii;
#define    sz(a)              long((a).size())
#define    pb                 push_back
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end()
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define    present(c,x)       ((c).find(x) != (c).end())
#define    cpresent(c,x)      (find(all(c),x) != (c).end())
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "

ll vis[202000],c[220000],ans[220000];
vi g[220000],d[220000];

vi dfs(ll s)
{
  vis[s]=1;
  ll i,j;
  vi t;
  t.pb(c[s]);
  for(i=0;i<g[s].size();i++)
  {
    if(vis[g[s][i]]==0){
      vi temp=dfs(g[s][i]);
      for(j=0;j<temp.size();j++)
      {
        temp[j]-=d[s][i];
        if(temp[j]>=0)t.pb(temp[j]);
      }
      //t.insert(t.begin(),temp.begin(),temp.end());

    }
  }

  ans[s]=t.size();
  return t;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n,i;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>c[i];
  }
  for(i=2;i<=n;i++)
  {
    ll x,y;
    cin>>x>>y;
    g[i].pb(x);
    g[x].pb(i);
     d[i].pb(y);
    d[x].pb(y);

  }

  dfs(1);
  for(i=1;i<=n;i++)
    cout<<ans[i]-1<<" ";

  return 0;
 }


/*

*/
/*
    link for using below tools::
    https://github.com/amit-nits/justforsharing/tree/master/debugger
*/
#define dbg(...)
#define db(...)
#define dbgl(...)
#define assrt(c)
#include "bits/stdc++.h"

using namespace std;using ll=long long;using ld = long double;
#define _(_1, _2, _3, _4, NAME, ...) NAME
#define f3(i, a, b, inc) for(int i = (a) - (inc < 0); (inc) > 0 ? i < (b) : i >= (b); i += (inc))
#define f2(i, a, b) f3(i, a, b, 1 - 2*(a > b))
#define f1(i, n) f2(i, 0, n)
#define f0(i) f2(i, 0, n)
#define fr(...) _(__VA_ARGS__, f3, f2, f1 , f0)(__VA_ARGS__)
#define trav(i,x) for(auto& i: x)
#define sz(x) ((int)(x).size())
#define len(x) ((int)(x).length())
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define all(x) begin(x),end(x)
const int mod = 1e9+7,inf = 1e9 , N = 2e5 + 1;
const ll MOD = 1e9+7,INF = 1e19; ld tic,tac;
int tc = 1;
ll n,cnt;
ll dis[N],in[N],out[N],tim[N],a[N];
vector< pair<ll,ll> >g[N];
vector<ll>tree[4*N];

int dfs(ll u,ll par,ll tot)
{
    cnt++;
    in[u]=cnt;
    tim[cnt]=u;
    dis[u]=tot;
    fr(i,g[u].size())
    {
        int v=g[u][i].f;
        if(v==par) continue;
        dfs(v,u,tot+g[u][i].s);
    }
    out[u]=cnt;
}

void build(int node,int b,int e)
{
    if(b==e)
    {
        tree[node].pb(dis[tim[b]]-a[tim[b]]);
        return ;
    }
    int l=2*node,r=l+1;
    int mid=(b+e)/2;
    build(l,b,mid);
    build(r,mid+1,e);
    tree[node].resize(tree[l].size()+tree[r].size());
    merge(all(tree[l]),all(tree[r]),tree[node].begin());
}
ll query(int node,int b,int e,int i,int j,ll val)
{
    if(i>e||j<b)
        return 0;
    if(b>=i&&e<=j)
    {
        int pos=upper_bound(all(tree[node]),val)-tree[node].begin();
        return pos;
    }
    int l=2*node;
    int r=l+1;
    int mid=(b+e)/2;
    return query(l,b,mid,i,j,val) + query(r,mid+1,e,i,j,val);
}

void solve(){
    cin>>n;
    fr(i,n)
    {
        cin>>a[i+1];
    }
    fr(i,2,n+1){
        ll p,q;
        cin>>p>>q;
        g[p].eb(i,q);
        g[i].eb(p,q);
    }
    cnt=0;
    dfs(1,0,0);
    build(1,1,n);
    fr(i,1,n+1)
        cout<<query(1,1,n,in[i]+1,out[i],dis[i])<<" ";
    cout<<endl;
}
int main(){
    ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);cout << fixed << setprecision(10);
    if(tc != 1)cin>>tc;
    for (int i = 1; i <= tc; ++i){
        // n = i;
        if(!ONLINE_JUDGE) cerr << "\nWhile solving TC " << i << ":\n", tic = clock();
        solve();
        if(!ONLINE_JUDGE) tac = clock(), cerr << "\nTC " << i << " done in:: " << 1000 * (tac-tic) / CLOCKS_PER_SEC << " ms\n";
    }
    if(!ONLINE_JUDGE) cerr << "\nGG in: " << 1000 * ((ld)clock()) / CLOCKS_PER_SEC << " ms\n";
    return 0;
}


//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll>
#define ull unsigned ll
#define vll vector<ll>
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
vector<pll> depth[2*100000+1];
vll v[2*100000+1];
ll intime[2*100000+1];
ll outtime[2*100000+1];
ll timer=0;
ll level[2*100000+1];
ll disfromroot[2*100000+1];
ll edge[2*100000+1];
umap<ll,ll> vintime;
ll answers[2*100000+1];
void dfs(int u,int p=-1)
{
  if(p!=-1)
  {
      level[u]=level[p]+1;
      disfromroot[u]=disfromroot[p]+edge[u];
  }
  intime[u]=timer++;
  vintime[intime[u]]=(ll)u;
  for(auto x:v[u])
  {
      if(x!=p)
      {
          dfs(x,u);
      }
  }
  outtime[u]=timer++;
  depth[level[u]].pb({intime[u],outtime[u]});
}
ll dr(int parentvertex,int child)
{
    return disfromroot[child]-disfromroot[parentvertex];
}
void dfsforanswer(int u,int p=-1)
{
    for(auto x:v[u])
    {
        if(x!=p)
        {
            dfsforanswer(x,u);
            answers[u]+=answers[x];
        }
    }
}
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
if(n==1)
{
    cout<<0;
    return;
}
ll vals[n+1];
for(int i=1;i<=n;i++)
{
  cin>>vals[i];
}
for(int i=2;i<=n;i++)
{
    cin>>a>>b;
    v[i].pb(a);
    v[a].pb(i);
    edge[i]=b;
}
level[1]=0;
disfromroot[1]=0;
dfs(1);
for(int i=0;i<=n;i++)
{
    sor(depth[i]);
}
for(int i=2;i<=n;i++)
{
   int l=0;
   int r=level[i]-1;
   int in=intime[i];
   int mid;
   //deb(r);
   //deb(in);
   while(l<=r)
   {
       mid=(l+r)/2;
       pll pa={intime[i],0};
       auto it=lb(depth[mid],pa);
       it--;
       pa=*it;
       int p=vintime[pa.fi];
       if(dr(p,i)<=vals[i])
       r=mid-1;
       else
       l=mid+1;
    //   if(i==4)
    //   {
    //   deb(l);
    //   deb(r);
    //   }
   }
   if(r>=0)
   {
       pll pa={intime[i],0};
       auto it=lb(depth[r],pa);
       it--;
       pa=*it;
       int p=vintime[pa.fi];
       answers[p]--;
   }

   //return ;
}
for(int i=1;i<=n;i++)
{
answers[i]+=v[i].size()-1;
}
answers[1]++;
dfsforanswer(1);
for(int i=1;i<=n;i++)
{
    cout<<answers[i]<<' ';
}
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}


//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll>
#define ull unsigned ll
#define vll vector<ll>
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
vector<pll> depth[2*100000+1];
vll v[2*100000+1];
ll intime[2*100000+1];
ll outtime[2*100000+1];
ll timer=0;
ll level[2*100000+1];
ll disfromroot[2*100000+1];
ll edge[2*100000+1];
umap<ll,ll> vintime;
ll answers[2*100000+1];
void dfs(int u,int p=-1)
{
  if(p!=-1)
  {
      level[u]=level[p]+1;
      disfromroot[u]=disfromroot[p]+edge[u];
  }
  intime[u]=timer++;
  vintime[intime[u]]=(ll)u;
  for(auto x:v[u])
  {
      if(x!=p)
      {
          dfs(x,u);
      }
  }
  outtime[u]=timer++;
  depth[level[u]].pb({intime[u],outtime[u]});
}
ll dr(int parentvertex,int child)
{
    return disfromroot[child]-disfromroot[parentvertex];
}
void dfsforanswer(int u,int p=-1)
{
    for(auto x:v[u])
    {
        if(x!=p)
        {
            dfsforanswer(x,u);
            answers[u]+=answers[x];
        }
    }
}
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
ll vals[n+1];
for(int i=1;i<=n;i++)
{
  cin>>vals[i];
}
for(int i=2;i<=n;i++)
{
    cin>>a>>b;
    v[i].pb(a);
    v[a].pb(i);
    edge[i]=b;
}
level[1]=0;
disfromroot[1]=0;
dfs(1);
for(int i=0;i<=n;i++)
{
    sor(depth[i]);
}
for(int i=2;i<=n;i++)
{
   int l=0;
   int r=level[i]-1;
   int in=intime[i];
   int mid;
   //deb(r);
   //deb(in);
   while(l<=r)
   {
       mid=(l+r)/2;
       pll pa={intime[i],0};
       auto it=lb(depth[mid],pa);
       it--;
       pa=*it;
       int p=vintime[pa.fi];
       if(dr(p,i)<=vals[i])
       r=mid-1;
       else
       l=mid+1;
    //   if(i==4)
    //   {
    //   deb(l);
    //   deb(r);
    //   }
   }
   if(r>=0)
   {
       pll pa={intime[i],0};
       auto it=lb(depth[r],pa);
       it--;
       pa=*it;
       int p=vintime[pa.fi];
       answers[p]--;
   }

   //return ;
}
for(int i=1;i<=n;i++)
{
answers[i]+=v[i].size()-1;
}
answers[1]++;
dfsforanswer(1);
for(int i=1;i<=n;i++)
{
    cout<<answers[i]<<' ';
}
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

const int N = 2e5 + 11;

vector<pair<int,ll> > v[N];
ll a[N];
int prr[N];
vector<int> vv;
ll deep[N];
int ans[N];

int up_ans(int x)
{
    int l=0,r=vv.size()-1;
    while (r-l>1)
    {
        int mid=(l+r)/2;
        if (deep[x]-deep[vv[mid]]<=a[x]) r=mid; else l=mid;
    }
    if (deep[x]-deep[vv[l]]<=a[x]) return vv[l];
    return vv[r];
}

void dfs(int l)
{
    vv.pb(l);
    int p=up_ans(l);
    ans[prr[l]]++;
    ans[prr[p]]--;
    for (int j=0; j<v[l].size(); j++)
    {
        int to=v[l][j].ff;
        deep[to]=deep[l]+v[l][j].ss;
        dfs(to);
        ans[l]+=ans[to];
    }
    vv.pop_back();
}

int main()
{
    int n;
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    for (int i=2; i<=n; i++)
    {
        int pr,w;
        cin>>pr>>w;
        v[pr].pb(mp(i,w));
        prr[i]=pr;
    }
    dfs(1);
    for (int i=1; i<=n; i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define double long double
const  double pi = acos(-1.0);
const  double eps = 1e-6;
using namespace std;

const int N = 2e5 + 10;
const int L = 20;
int n;
int a[N];
vector <pair <int, ll> > g[N];
vector <int> gr[N];
int up[N][L];

ll dp[N], add[N], ans[N], sub[N];
int pred[N], deg[N];
bool used[N];
void dfs(int v, int p){
    up[v][0] = p;
    for (int i = 1; i < L; i++)
        up[v][i] = up[up[v][i - 1]][i - 1];

    for (auto to : g[v]){
        dp[to.fr] = dp[v] + to.sc;
        dfs(to.fr, v);
    }
}

void solve(){
    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;
        g[p].pb({i, w});
        deg[p]++;
        gr[i].pb(p);
        pred[i] = p;
    }
    dfs(1, 1);
    for (int i = 2; i <= n; i++){
        ll len = dp[i] - a[i];
        if (len > dp[pred[i]]) continue;
        int v = i;
        for (int j = L - 1; j >= 0; j--)
            if (len <= dp[up[v][j]]) v = up[v][j];
        sub[v]--;
        add[i]++;
        //cout << i << " " << v << endl;
    }
    //for (int i = 1; i <= n; i++)
    //    cout << add[i] << " ";
    //cout << endl;

    deque <int> lists;

    for (int i = 1; i <= n; i++)
        if (deg[i] == 0) lists.pb(i), used[i] = true;

    while (lists.size() > 0){
        int v = lists.front();
        lists.pop_front();
        ans[pred[v]] += add[v] + sub[v] + ans[v];
        deg[pred[v]]--;
        if (deg[pred[v]] == 0 && !used[pred[v]]){
            used[pred[v]] = true;
            lists.pb(pred[v]);
        }
    }

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

int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(15);
    //freopen("input.txt", "r", stdin);//freopen("output.txt", "w", stdout);
    //freopen("expect.in","r",stdin); freopen("expect.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++){
         solve();
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;

#ifdef LOCAL
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {return '"' + s + '"';}
string to_string(const char* s) {return to_string((string) s);}
string to_string(bool b) {return (b ? "true" : "false");}
string to_string(vector<bool> v) {bool first = true;string res = "{";for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;}
template <size_t N>string to_string(bitset<N> v) {string res = "";for (size_t i = 0; i < N; i++) {res += static_cast<char>('0' + v[i]);}return res;}
template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define trace(a, n) cerr << #a << "[" << n <<  "] = ["; for (int i = 0; i < n; i++) cerr << a[i] << ", "; cerr << "]\n"
#else
#define debug(...) 42
#define trace(a, n) 42
#endif

#define int long long
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define uint unsigned int
#define pi pair<int, int>
#define pl pair<ll, ll>

template <class L, class R> istream& operator>> (istream& is, pair<L, R>& P) { return is >> P.ff >> P.ss; }
template <class T> istream& operator>> (istream& is, vector<T>& V) { for (auto& e : V) is >> e; return is; }
template <class L, class R> ostream& operator<< (ostream& os, pair<L, R>& P) { return os << P.ff << " " << P.ss; }
template <class T> ostream& operator<< (ostream& os, vector<T>& V) { for (auto& e : V) os << e << " "; return os; }
template <class T = int> int bsl(vector<T> a, T x) { int lo = 0; int hi = sz(a) - 1; int req = -1; int mid = lo + (hi - lo) / 2; while (lo <= hi) { if (a[mid] <= x) { req = mid; lo = mid + 1; } else { hi = mid - 1; } mid = lo + (hi - lo) / 2; } return req; }
template <class T = int> int bsg(vector<T> a, T x) { int lo = 0; int hi = sz(a) - 1; int req = -1; int mid = lo + (hi - lo) / 2; while (lo <= hi) { if (a[mid] >= x) { req = mid; hi = mid - 1; } else { lo = mid + 1; } mid = lo + (hi - lo) / 2; } return req; }

template <typename Map> bool map_compare (Map const &lhs, Map const &rhs) { return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());}
template <class T> void remove_dups (vector<T>& V) { V.erase(unique(V.begin(), V.end()), V.end()); }

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 rng(seed);
inline long long randint (long long l, long long r) { uniform_int_distribution<long long> dis(l, r); return dis(rng); }
inline double random (double l, double r) { uniform_real_distribution<double> dis(l, r); return dis(rng); }
inline double randn() { normal_distribution<double> dis; return dis(rng); }
inline double rdn (double std_dev, double mean) { return std_dev * randn() + mean; }

const int infi = 2e9;
const long long infl = 4e18;
const int md = 998244353;
const double PI = 3.14159265358979323846;

inline long long modpow(long long x, long long n) { long long res = 1; while (n > 0) { if (n % 2) res = (res * x) % md; x = (x * x) % md; n /= 2; } return res; }
inline long long inv(long long x) {return modpow(x, md-2);}
inline bool imax (long long& a, long long b) { bool res = (b > a); a = max(a, b); return res;}
inline bool emax (long long& a, long long b) { bool res = (b >= a); a = max(a, b); return res;}
inline bool imin (long long& a, long long b) { bool res = (b < a); a = min(a, b); return res;}
inline bool emin (long long& a, long long b) { bool res = (b <= a); a = min(a, b); return res;}
inline long long log_2 (long long n) { return (n > 1ll)? 1ll + log_2(n/2): 0ll;}
inline long long log_10 (long long n) { return (n > 9ll)? 1ll + log_10(n/10): 0ll;}
inline void add(long long& a, long long b) {a = ((a % md) + (b % md)) % md;}
inline void sub(long long& a, long long b) {a = ((a % md) - (b % md) + md) % md;}
inline void mul(long long& a, long long b) {a = ((a % md) * (b % md)) % md;}
inline long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r;} return a; }
inline long long ceil_div(long long a, long long b) { return a / b + ((a ^ b) > 0 && a % b != 0); }

template <class T>
struct cmp {
  bool operator() (const T& x, const T& y) const {
    return x > y;
  }
  typedef T first_argument_type;
  typedef T second_argument_type;
  typedef bool result_type;
};

signed main() {
#ifdef READ_FILE
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);

  // Approach: 1 (May exceed time limit)

  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<vector<pi>> g(n + 1);
  for (int i = 1; i <= n - 1; i++) {
    int p, w;
    cin >> p >> w;
    g[p].eb(i + 1, w);
    g[i + 1].eb(p, w);
  }
  vector<int> cnt(n + 1), depth(n + 1);
  vector<pi> path;
  function <void (int, int)> Dfs = [&] (int v, int p) {
    cnt[v] = 1;
    int idx = lower_bound(all(path), make_pair(depth[v] - a[v], -1LL)) - path.begin();
    --idx;
    if (idx >= 0) cnt[path[idx].ss]--;
    path.eb(depth[v], v);
    for (pi e : g[v]) {
      int u = e.ff;
      if (u == p) continue;
      depth[u] = depth[v] + e.ss;
      Dfs(u, v);
      cnt[v] += cnt[u];
    }
    path.pop_back();
  };
  Dfs(1, -1);
  for (int i = 1; i <= n; i++) cout << cnt[i] - 1 << " ";
  cout << "\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int f(string s) {
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        ans = ans * 10 + int(s[i] - '0');
    }
    return ans;
}
string y(int a, int p) {
    if (a == 0) {
        return "0";
    }
    string ans = "";
    while (a != 0) {
        ans += char('0' + (a % 10));
        a = a / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() == 1 && p == 1) {
        ans = "0" + ans;
    }
    return ans;
}

double toi(string s) {
    long double ans = 0.0;
    vector <string> r;
    string s1;
    int i = 0;
    while (i < s.size()) {
        s1 = "";
        while (i < s.size() && s[i] != '.') {
            s1 += s[i];
            i++;
        }
        if (s1 != "") {
            r.push_back(s1);
        }
        i++;
    }
    for (string w : r) {
        if (w.size() == 2 && w != r[0]) {
            double e = f(w) / 100.0;
            ans = double(ans) + e;
        }
        else {
            ans = double(ans * 1000.0 + f(w));
        }
    }
    return ans;
}

string tost(double a) {
    if (a == 0) {
        return "0";
    }
    long double b = a;
    string x1 = "";
    if (double(int(b)) != b) {
        int t = (b - (int(b))) * 100000;
        t = (t + 1) / 1000;
        //cout << t << "\n";;
        x1 = y(t, 1);
    }
    //cout << x1 << "\n";
    int u = int(b);
    vector <string> r;
    while (u != 0) {
        int o = u % 1000;
        r.push_back(y(o, 0));
        u = u / 1000;
    }
    string ans = "";
    if (r.size() == 0) {
        return "0." + x1;
    }
    ans += r[r.size() - 1];
    for (int i = r.size() - 2; i > -1; i--) {
        ans += '.';
        ans += r[i];
    }
    if (x1 != "") {
        ans += '.' + x1;
    }
    return ans;
}

int main()
{
    cout.precision(2);
    cout << fixed;
    //cout << toi("128.908.87");
    //cout << y(128);
    double ans = 0;
    string s;
    cin >> s;
    int i = 0;
    while (i < s.size()) {
        string s1 = "";
        while (i < s.size() && (s[i] <= '9' && s[i] >= '0' || s[i] == '.')) {
            s1 += s[i];
            i++;
        }
        if (s1 != "") {
            double u = toi(s1);
            //cout << u << "\n";
            ans += u;
        }
        i++;
    }
    //cout << ans << "\n";
    cout << tost(ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long f(string s) {
    long long ans = 0;
    for (long long i = 0; i < s.size(); i++) {
        ans = ans * 10 + int(s[i] - '0');
    }
    return ans;
}
string y(long long a, long long p) {
    if (a == 0) {
        return "0";
    }
    string ans = "";
    while (a != 0) {
        ans += char('0' + (a % 10));
        a = a / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() == 1 && p == 1) {
        ans = "0" + ans;
    }
    return ans;
}

double toi(string s) {
    long double ans = 0.0;
    vector <string> r;
    string s1;
    long long i = 0;
    while (i < s.size()) {
        s1 = "";
        while (i < s.size() && s[i] != '.') {
            s1 += s[i];
            i++;
        }
        if (s1 != "") {
            r.push_back(s1);
        }
        i++;
    }
    for (string w : r) {
        if (w.size() == 2 && w != r[0]) {
            double e = f(w) / 100.0;
            ans = double(ans) + e;
        }
        else {
            ans = double(ans * 1000.0 + f(w));
        }
    }
    return ans;
}

string tost(double a) {
    if (a == 0) {
        return "0";
    }
    long double b = a;
    string x1 = "";
    if (double(int(b)) != b) {
        long long t = (b - (int(b))) * 100000;
        t = (t + 1) / 1000;
        //cout << t << "\n";;
        x1 = y(t, 1);
    }
    //cout << x1 << "\n";
    long long u = int(b);
    vector <string> r;
    while (u != 0) {
        long long o = u % 1000;
        r.push_back(y(o, 0));
        u = u / 1000;
    }
    string ans = "";
    if (r.size() == 0) {
        return "0." + x1;
    }
    ans += r[r.size() - 1];
    for (long long i = r.size() - 2; i > -1; i--) {
        ans += '.';
        ans += r[i];
    }
    if (x1 != "") {
        ans += '.' + x1;
    }
    return ans;
}

int main()
{
    cout.precision(2);
    cout << fixed;
    //cout << toi("128.908.87");
    //cout << y(128);
    double ans = 0;
    string s;
    cin >> s;
    long long i = 0;
    while (i < s.size()) {
        string s1 = "";
        while (i < s.size() && (s[i] <= '9' && s[i] >= '0' || s[i] == '.')) {
            s1 += s[i];
            i++;
        }
        if (s1 != "") {
            double u = toi(s1);
            //cout << u << "\n";
            ans += u;
        }
        i++;
    }
    //cout << ans << "\n";
    cout << tost(ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>

using namespace std;
char s[1010];
int main()
{
    scanf ("%s",s);
    long long ans=0,val=0,t_l=0,l=strlen(s),num_flag=0,dot_flag=0;
    for (long long i=0; i<l; i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            if (num_flag)
            {
//                cout<<val<<endl;
                if(t_l==2) ans+=val;
                else ans+=val*100;
                num_flag=0;
                dot_flag=0;
                val=0;
                t_l=0;
            }
        }
        else if (s[i]>='0'&&s[i]<='9')
        {
            val=val*10+s[i]-'0';
            num_flag=1;
            if (dot_flag)
            {
                t_l++;
            }
        }
        else
        {
            dot_flag=1;
            t_l=0;
        }
    }
    if (num_flag)
    {
//                cout<<val<<endl;
        if(t_l==2) ans+=val;
        else ans+=val*100;
        num_flag=0;
        dot_flag=0;
        val=0;
        t_l=0;
    }
//    cout<<ans<<endl;
    if (ans<100)
    {
        printf ("%I64d.%02I64d\n",ans/100,ans%100);
    }
    else
    {
        char a[20],top=0;
        if (ans%100!=0)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]='.';
            ans*=100;
        }
        ans/=100;
        int tmp=0;
        while (ans)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            tmp++;
            if (tmp==3)
            {
                a[top++]='.';
                tmp=0;
            }
        }
        for (int i=top-1; i>=0; i--) printf ("%c",a[i]);
        printf ("\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>

using namespace std;
char s[1010];
int main()
{
    scanf ("%s",s);
    long long ans=0,val=0,t_l=0,l=strlen(s),num_flag=0,dot_flag=0;
    for (long long i=0; i<l; i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            if (num_flag)
            {
//                cout<<val<<endl;
                if(t_l==2) ans+=val;
                else ans+=val*100;
                num_flag=0;
                dot_flag=0;
                val=0;
                t_l=0;
            }
        }
        else if (s[i]>='0'&&s[i]<='9')
        {
            val=val*10+s[i]-'0';
            num_flag=1;
            if (dot_flag)
            {
                t_l++;
            }
        }
        else
        {
            dot_flag=1;
            t_l=0;
        }
    }
    if (num_flag)
    {
//                cout<<val<<endl;
        if(t_l==2) ans+=val;
        else ans+=val*100;
        num_flag=0;
        dot_flag=0;
        val=0;
        t_l=0;
    }
    if (ans<=100)
    {
        printf ("%I64d.%02I64d\n",ans/100,ans%100);
    }
    else
    {
        char a[20],top=0;
        if (ans%100!=0){a[top++]=ans%10+'0';
        ans/=10;
        a[top++]=ans%10+'0';
        ans/=10;
        a[top++]='.';}
        int tmp=0;
        while (ans)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            tmp++;
            if (tmp==3)
            {
                a[top++]='.';
                tmp=0;
            }
        }
        for (int i=top-1;i>=0;i--) printf ("%c",a[i]);
        printf ("\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>

using namespace std;
char s[1010];
int main()
{
    scanf ("%s",s);
    long long ans=0,val=0,t_l=0,l=strlen(s),num_flag=0,dot_flag=0;
    for (long long i=0; i<l; i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            if (num_flag)
            {
//                cout<<val<<endl;
                if(t_l==2) ans+=val;
                else ans+=val*100;
                num_flag=0;
                dot_flag=0;
                val=0;
                t_l=0;
            }
        }
        else if (s[i]>='0'&&s[i]<='9')
        {
            val=val*10+s[i]-'0';
            num_flag=1;
            if (dot_flag)
            {
                t_l++;
            }
        }
        else
        {
            dot_flag=1;
            t_l=0;
        }
    }
    if (num_flag)
    {
//                cout<<val<<endl;
        if(t_l==2) ans+=val;
        else ans+=val*100;
        num_flag=0;
        dot_flag=0;
        val=0;
        t_l=0;
    }
    if (ans<=100)
    {
        printf ("%I64d.%02I64d\n",ans/100,ans%100);
    }
    else
    {
        char a[20],top=0;
        a[top++]=ans%10+'0';
        ans/=10;
        a[top++]=ans%10+'0';
        ans/=10;
        a[top++]='.';
        int tmp=0;
        while (ans)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            tmp++;
            if (tmp==3)
            {
                a[top++]='.';
                tmp=0;
            }
        }
        for (int i=top-1;i>=0;i--) printf ("%c",a[i]);
        printf ("\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>

using namespace std;
char s[1010];
int main()
{
    scanf ("%s",s);
    long long ans=0,val=0,t_l=0,l=strlen(s),num_flag=0,dot_flag=0;
    for (long long i=0; i<l; i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            if (num_flag)
            {
//                cout<<val<<endl;
                if(t_l==2) ans+=val;
                else ans+=val*100;
                num_flag=0;
                dot_flag=0;
                val=0;
                t_l=0;
            }
        }
        else if (s[i]>='0'&&s[i]<='9')
        {
            val=val*10+s[i]-'0';
            num_flag=1;
            if (dot_flag)
            {
                t_l++;
            }
        }
        else
        {
            dot_flag=1;
            t_l=0;
        }
    }
    if (num_flag)
    {
//                cout<<val<<endl;
        if(t_l==2) ans+=val;
        else ans+=val*100;
        num_flag=0;
        dot_flag=0;
        val=0;
        t_l=0;
    }
//    cout<<ans<<endl;
    if (ans<=100)
    {
        printf ("%I64d.%02I64d\n",ans/100,ans%100);
    }
    else
    {
        char a[20],top=0;
        if (ans%100!=0)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]='.';
            ans*=100;
        }
        ans/=100;
        int tmp=0;
        while (ans)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            tmp++;
            if (tmp==3)
            {
                a[top++]='.';
                tmp=0;
            }
        }
        for (int i=top-1; i>=0; i--) printf ("%c",a[i]);
        printf ("\n");
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <set>
#include <stack>
#include <queue>

using namespace std;
char s[1010];
int main()
{
    scanf ("%s",s);
    long long ans=0,val=0,t_l=0,l=strlen(s),num_flag=0,dot_flag=0;
    for (long long i=0; i<l; i++)
    {
        if (s[i]>='a'&&s[i]<='z')
        {
            if (num_flag)
            {
//                cout<<val<<endl;
                if(t_l==2) ans+=val;
                else ans+=val*100;
                num_flag=0;
                dot_flag=0;
                val=0;
                t_l=0;
            }
        }
        else if (s[i]>='0'&&s[i]<='9')
        {
            val=val*10+s[i]-'0';
            num_flag=1;
            if (dot_flag)
            {
                t_l++;
            }
        }
        else
        {
            dot_flag=1;
            t_l=0;
        }
    }
    if (num_flag)
    {
//                cout<<val<<endl;
        if(t_l==2) ans+=val;
        else ans+=val*100;
        num_flag=0;
        dot_flag=0;
        val=0;
        t_l=0;
    }
//    cout<<ans<<endl;
    if (ans<100)
    {
        printf ("%I64d.%02I64d\n",ans/100,ans%100);
    }
    else
    {
        char a[20],top=0;
        if (ans%100!=0)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]=ans%10+'0';
            ans/=10;
            a[top++]='.';
            ans*=100;
        }
        ans/=100;
        int tmp=0;
        while (ans)
        {
            a[top++]=ans%10+'0';
            ans/=10;
            tmp++;
            if (!ans) break;
            if (tmp==3)
            {
                a[top++]='.';
                tmp=0;
            }
        }
        for (int i=top-1; i>=0; i--) printf ("%c",a[i]);
        printf ("\n");
    }
    return 0;
}