#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using oset = tree<T, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update>;

//#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
int inf = 1e9;
int n;
vector<vector<int>> kids;
vector<int> p, s;
vector<int> ans;
vector<int> dep;
void slow(){
    int res = inf;
    for(auto x : kids[0]){
        int vv = s[x];
        s[x] = 0;
        set<pair<int, int>> gg;
        int time = 0;
        gg.insert({s[0], 0});
        while(!gg.empty()){
            int v = gg.rbegin()->second;
            ans[v] = min(ans[v], time);
            time++;
            for(auto x : kids[v]){
                gg.insert({s[x], x});
            }
            gg.erase({s[v], v});
        }
        s[x] = vv;
    }
}

void dfs(int v){
    for(auto u : kids[v]){
        dep[u] = dep[v]+1;
        dfs(u);
    }
}

vector<int> ord;

void initord(){
    set<pair<int, int>> gg;
    gg.insert({s[0], 0});
    while(!gg.empty()){
        int v = gg.rbegin()->second;
        ord.push_back(v);
        for(auto x : kids[v]){
            gg.insert({s[x], x});
        }
        gg.erase({s[v], v});
    }
}
vector<int> glav;
void dfs2(int v, int p){
    glav[v] = p;
    if(v == 0){
        for(auto u : kids[v]){
            dfs2(u, u);
        }
    }else{
        for(auto u : kids[v]){
            dfs2(u, p);
        }
    }
}
void solve() {
    int q ;
    cin >> n >> q;
    p.assign(n, 0);
    p[0] = -1;
    kids.assign(n, {});
    for(int i = 1; i < n; ++i){
        cin >> p[i];
        p[i]--;
        kids[p[i]].push_back(i);
    }
    s.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
    }
    ans.assign(n, inf);
    dep.assign(n, 0);
    dfs(0);
    initord();

    vector<int> cnt(n);
    glav.assign(n, 0);
    dfs2(0, 0);
    ans[0] = 0;
    pair<int, int> mx1, mx2;
    mx1 = {0, 0};
    mx2 = {0,0}; //в какой вершине и сколько
    for(int i = 1; i < n; ++i){
        int v = ord[i];
        int g = glav[v];
        cnt[g]++;
        if(mx1.second == g){
            ans[v] = i - mx2.first - 1;
        }else{
            ans[v] = i - mx1.first - 1;
        }
        pair<int, int> nw = {cnt[g], g};
        if(mx1.second == g){
            mx1 = nw;
        }else{
            if(nw.first > mx1.first){
                mx2 = mx1;
                mx1 = nw;
            }else if(nw.first > mx2.first){
                mx2 = nw;
            }
        }
        cout << mx1.first << " " <<  mx1.second << '\n';
        cout << mx2.first << " " <<  mx2.second << '\n';
        cout << endl;
    }

    while(q--){
        int d;
        cin >>d;
        d--;
        cout << ans[d] << " ";
    }
}

signed main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
        cout << '\n';
    }
    return 0;
}
