#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define sll __int128
#define size(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int long long

mt19937 rnd(time(0));

void dfs(int v, int w, vector<vector<int>> &g, vector<int> &s){
    for (auto to : g[v]){
        dfs(to, min(w, s[v]), g, s);
    }
    s[v] = min(s[v], w);
}

int mx = 0, sm = 0;

void dfs2(int v, vector<vector<int>> &g, vector<int> &s, vector<int> &ch, vector<int> &ans){
    vector<pair<int, int>> a;
    for (auto to : g[v]){
        a.push_back({-s[to], to});
    }
    sort(all(a));
    for (auto [w, to] : a){
        ans[to] = sm - mx;
        dfs2(to, g, s, ch, ans);
        ch[v] += ch[to];
    }
    mx = max(mx, ch[v]);
}

void solve(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n);
    vector<int> pr(n), nxt(n, -1);
    for (int i = 1; i < n; i++){
        int p; cin >> p; p--;
        g[p].push_back(i);
        pr[i] = p;
        if (p + 1 == i){
            nxt[p] = i;
        }
    }
    vector<int> s(n);
    for (auto &x : s){
        cin >> x;
    }
    vector<int> ch(n), ans(n);
    dfs2(0, g, s, ch, ans);
    for (int i = 0; i < n; i++){
        int x; cin >> x; x--;
        cout << ans[x];
    }
}

signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ttt = 1;
    //cin >> ttt;
    while (ttt--){
        solve();
    }
}
