#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll>gr[300002];
vector<pair<pair<ll,ll>,ll>>srt;
ll n,q,p[300002],s[300002],tin[300002],tout[300002],t,x,a[300002],stin[1200002],i,sout[1200002],ord[300002];
void dfs(ll v,ll p){
    s[v]=1;
    tin[v]=t;
    t++;
    for(auto u:gr[v]){
        if(u!=p){
            dfs(u,v);
            s[v]+=s[u];
        }
    }
    tout[v]=t;
    t++;
}
void bin(ll v, ll l, ll r){
    if(l==r){
        stin[v]=srt[l].second;
        return;
    }
    ll m=(l+r)/2;
    bin(2*v,l,m);
    bin(2*v+1,m+1,r);
    if(tin[stin[2*v]]>tin[stin[2*v+1]]){
        stin[v]=stin[2*v];
    }else{
        stin[v]=stin[2*v+1];
    }
}
void bout(ll v, ll l, ll r){
    if(l==r){
        sout[v]=srt[l].second;
        return;
    }
    ll m=(l+r)/2;
    bout(2*v,l,m);
    bout(2*v+1,m+1,r);
    if(tout[sout[2*v]]<tout[sout[2*v+1]]){
        sout[v]=sout[2*v];
    }else{
        sout[v]=sout[2*v+1];
    }
}
ll fin(ll v, ll l, ll r,ll x){
    if(l==r){
        return stin[v];
    }
    ll m=(l+r)/2;
    if(tin[stin[2*v]]>x){
        return fin(2*v,l,m,x);
    }else{
        return fin(2*v+1,m+1,r,x);
    }
}
ll fout(ll v, ll l, ll r,ll x){
    if(l==r){
        return sout[v];
    }
    ll m=(l+r)/2;
    if(tout[sout[2*v]]<x){
        return fout(2*v,l,m,x);
    }else{
        return fout(2*v+1,m+1,r,x);
    }
}
signed main(){
    cin >> n >> q;
    for(i=2;i<=n;i++){
        cin >>p[i]; 
        gr[p[i]].push_back(i);
    }
    for(i=1;i<=n;i++){
        cin >> a[i];
    }
    dfs(1,-1);
    for(i=1;i<=n;i++){
        srt.push_back({{s[i],a[i]},i});
    }
    sort(srt.begin(),srt.end());
    for(i=0;i<n;i++){
        ord[srt[i].second]=i;
    }
    bin(1,1,n);
    bout(1,1,n);
    while(q--){
        cin >> x;
        ll ans1=fin(1,1,n,tin[x]);
        ll ans2=fout(1,1,n,tout[x]);
        if(ord[ans1]<ord[x]){
            ans1=ord[x]-s[ans1];
        }else{
            ans1=1e9;
        }
        if(ord[ans2]<ord[x]){
            ans2=ord[x]-s[ans2];
        }else{
            ans2=1e9;
        }
        cout << min(ans1,ans2) << ' ';
    }
    return 0;
}