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

struct SN {
    int val;
    SN* prev;
    SN(int v, SN* p) : val(v), prev(p) {}
};

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

    int n;
    cin >> n;
    vector<int> prt(n + 1);
    vector<vector<int>> child(n + 1);
    for (int i = 2; i <= n; ++i) {
        int p;
        cin >> p;
        prt[i] = p;
        child[p].push_back(i);
    }
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vector<SN*> stp(n + 1, nullptr);
    vector<int> cnts(n + 1, 0);

    // BFS
    queue<int> q;
    q.push(1);
    stp[1] = new SN(a[1], nullptr);
    cnts[1] = 1;

    while (!q.empty()) {
        int u = q.front();
        q.pop();

        for (int v : child[u]) {
            SN* ctop = stp[u];
            int ccnt = cnts[u];
            int val = a[v];

            while (ctop != nullptr && ctop->val <= val) {
                SN* temp = ctop;
                ctop = ctop->prev;
                ccnt--;
            }

            ctop = new SN(val, ctop);
            ccnt++;
            stp[v] = ctop;
            cnts[v] = ccnt;

            q.push(v);
        }
    }

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

    return 0;
}