#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2010;
//vector <int> g
void solve(){
    int n, q;
    cin >> n >> q;
    vector <int> p(n);
    for (int i = 1; i < n; ++i){
        cin >> p[i];
        --p[i];
        //g[p].push_back(i);
    }
    vector <int> s(n);
    for (int i = 0; i < n; ++i){
        cin >> s[i];
    }
    vector <int> ans(n);
    ans[0] = 0;
    for (int i = 1; i < n; ++i){
        ans[i] = ans[p[i]] + 1;
    }
    while (q--){
        int v;
        cin >> v;
        --v;
        cout << ans[v] << " ";
    }

}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
   // cin >> t;
    while (t--){
        solve();
        cout << "\n";
    }
}




