#include <bits/stdc++.h>

using namespace std;

template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
    for (auto& x : a) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& is, vector<T>& a) {
    for (auto& x : a) is << x << ' ';
    cout << '\n';
    return is;
}

template<typename T1, typename T2>
istream& operator>>(istream& is, vector<pair<T1, T2>>& a) {
    for (auto& x : a) is >> x.first >> x.second;
    return is;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& is, vector<pair<T1, T2>>& a) {
    for (auto& x : a) is << x.first << ' ' << x.second << '\n';
    return is;
}


template<typename T1, typename T2>
void amax(T1& a, T2 b) {
    a = max(a, b);
}
template<typename T1, typename T2>
void amin(T1& a, T2 b) {
    a = min(a, b);
}
#ifdef OTKR
bool local = true;
#else
bool local = false;
#endif // OTKR

#define int long long
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define pb emplace_back
#define push emplace

void solve();
void stress();
void precalc();

using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvpi = vector<vpi>;

const int ma = 3e5;
const int INF = 1e18;
const int mod = 1e9 + 7;

struct Mint{
    int x;
    Mint() : x(0) {}
    Mint(int x) : x(x) {}
    Mint operator+(const Mint& b) const {
        int res = x + b.x;
        if (res >= mod) res -= mod;
        return {res};
    }
    Mint operator-(const Mint& b) const {
        int res = x - b.x;
        if (res < 0) res += mod;
        return {res};
    }
    Mint operator*(const Mint& b) const {
        return {x * b.x % mod};
    }
    Mint operator==(const Mint& b) const {
        return x == b.x;
    }
};

struct Segtree{
    struct Node{

        Node operator+(const Node& b) const {
            Node res;

            return res;
        }
    };
    Node Make(int x, int i) {
        Node res;

        return res;
    }
    Node N;
    vector<Node> t;
    void build(int v, int l, int r,const vi& a) {
        if (l + 1 == r) {
            t[v] = Make(a[l], l);
        }
        int m = (l + r) / 2;
        build(v * 2, l, m, a);
        build(v * 2 + 1, m, r, a);
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    Segtree(const vi& a) : t(4 * sz(a)) {
        build(1, 0, sz(a), a);
    }
    void upd(int v, int l, int r, int i, int x) {
        if (l + 1 == r) {
            t[v] = Make(x, l);
        }
        int m = (l + r) / 2;
        if (i < m) {
            upd(v * 2, l, m, i, x);
        } else {
            upd(v * 2 + 1, m, r, i, x);
        }
        t[v] = t[v * 2] + t[v * 2 + 1];
    }
    Node get(int v, int nl, int nr, int ql, int qr) {
        if (nl >= qr || nr <= ql) return N;
        if (ql <= nl && nr <= qr) return t[v];
        int m = (nl + nr) / 2;
        return get(v * 2, nl, m, ql, qr) + get(v * 2 + 1, m, nr, ql, qr);
    }
};

signed main() {
    if (local) {
        freopen("input.txt", "r", stdin);
    }
    int t = 1; //cin >> t;
    while (t--) {
        solve();
    }
}

int brut2(int n, int m, vi& a) {
    //n == 2
    int ans = -INF;
    vi cur(n);
    for (int mask = 0; mask < (1 << m); mask++) {
        cur[0] = cur[1] = 0;
        vi f, s;
        for (int i = 0; i < m; i++) {
            if (((mask >> i) & 1) == 1) {
                f.pb(a[i]);
            } else {
                s.pb(a[i]);
            }
        }
        int res = 0;
        for (auto x : f) {
            cur[0] = x - cur[0];
        }
        for (auto x : s) {
            cur[1] = x - cur[1];
        }
        res = cur[0] + cur[1];
        if (ans < res) {
            cout << f << s;
            ans = res;
        }
    }
    return ans;
}

void solve() {
    int n, q; cin >> n >> q;
    vvi adj(n);
    int is = 1, cn = 0;
    vector<int> h(n);
    for (int i = 1; i < n; i++) {
        int p; cin >> p;
        p--;
        if (p == 1) cn++;
        h[i] = h[p] + 1;
        if (p != i - 1) is = 0;
        adj[p].pb(i);
    }
    vi ans(n, INF);
    vi s(n); cin >> s;
    if (cn <= 2 && is) {
        while (q--) {
            int x; cin >> x;
            cout << h[--x] << '\n';
        }
        exit(0);
    }
    vector<int> st2;
    for (int i = 0; i < n; i++) {
        st2.pb(i);
    }
    for (int k = 0; k < 200 && k < sz(st2); k++) {
        int st = st2[k];
        vi dp(n);
        int t = s[st];
        s[st] = 0;
        int v = 0, su = 0;
        priority_queue<pi> pq;
        for (auto x : adj[0]) {
            pq.push(s[x], x);
        }
        while (!pq.empty()) {
            su++;
            auto [c, u] = pq.top();
            pq.pop();
            dp[u] = dp[v] + 1;
            for (auto x : adj[u]) {
                pq.push(s[x], x);
            }
            v = u;
        }
        //cout << dp;
        for (int i = 0; i < n; i++) {
            amin(ans[i], dp[i]);
        }
        s[st] = t;
    }
    while (q--) {
        int x; cin >> x;
        cout << ans[--x] << ' ';
    }
}









