#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
using ll = long long;

typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9 + 7;
const ll inf_ = 1e18 + 7;
const int mod = 998244353;

struct Fast {
    vector<vector<int>> g;
    vector<int> s;
    vector<int> ans;

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

    void solve() {
        int n, q;
        cin >> n >> q;
        g.resize(n);
        for (int i = 1; i < n; i++) {
            int x;
            cin >> x;
            x--;
            g[x].push_back(i);
        }
        s.resize(n);
        ans.resize(n, inf);
        for (auto &i: s) cin >> i;
        ans[0] = 0;
        dfs(0);
        while (q--) {
            int x;
            cin >> x;
            x--;
            cout << ans[x] << ' ';
        }
    }
};

signed main() {
    int __ = 1;
    //cin >> __;
    while (__--) {
        Fast().solve();
        cout << '\n';
    }
    return 0;
}
