#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
    for (T& x : v) out << x << " ";
    return out;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2>& p) {
    out << p.first << " " << p.second;
    return out;
}

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using ld = long double;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

struct segtree {

    struct node {

        node() {}

        int x = 0, ps = -1e9, l = -1, r = -1;

    };

    segtree(int n) : n(n) {
        v.emplace_back();
    }

    void ext(int pos) {
        if (v[pos].l == -1) {
            v[pos].l = v.size();
            v.emplace_back();
        }
        if (v[pos].r == -1) {
            v[pos].r = v.size();
            v.emplace_back();
        }
    }

    void push(int pos, int tl, int tr) {
        ext(pos);
        if (v[pos].l != -1) {
            v[v[pos].l].x = max(v[v[pos].l].x, v[pos].ps);
            v[v[pos].l].ps = max(v[v[pos].l].ps, v[pos].ps);
        }
        if (v[pos].r != -1) {
            v[v[pos].r].x = max(v[v[pos].r].x, v[pos].ps);
            v[v[pos].r].ps = max(v[v[pos].r].ps, v[pos].ps);
        }
        v[pos].ps = -1e9;
    }

    int get(int l, int r) {
        return get(l, r, 0, 0, n - 1);
    }

    void upd(int l, int r, int x) {
        upd(l, r, x, 0, 0, n - 1);
    }

    int get(int l, int r, int pos, int tl, int tr) {
        if (tr < l || r < tl) return -1e9;
        if (l <= tl && tr <= r) return v[pos].x;
        ext(pos);
        push(pos, tl, tr);
        int m = (tl + tr) / 2;
        return max(get(l, r, v[pos].l, tl, m), get(l, r, v[pos].r, m + 1, tr));
    }

    void upd(int l, int r, int x, int pos, int tl, int tr) {
        if (r < tl || tr < l) return;
        if (l <= tl && tr <= r) {
            v[pos].x = max(v[pos].x, x);
            v[pos].ps = max(v[pos].ps, x);
            return;
        }
        push(pos, tl, tr);
        int m = (tl + tr) / 2;
        if (v[pos].l != -1) upd(l, r, x, v[pos].l, tl, m);
        if (v[pos].r != -1) upd(l, r, x, v[pos].r, m + 1, tr);
        v[pos].x = max((v[pos].l == -1 ? 0 : v[v[pos].l].x), (v[pos].r == -1 ? 0 : v[v[pos].r].x));
    }

    int n;
    vector<node> v;

};

int n;
vector<vector<int>> g;
vector<int> ans, ord, pos;
vector<vector<int>> res;

void dfs(int v) {
    for (int to : g[v]) {
        dfs(to);
    }

    segtree st(n);
    for (int i = 0; i < g[v].size(); i++) {
        for (int x : res[g[v][i]]) {
            ans[ord[x]] = min(ans[ord[x]], x - st.get(x, x));
        }
        for (int j = 0; j < res[g[v][i]].size(); j++) {
            st.upd(res[g[v][i]][j], n - 1, j + 1);
        }
    }
    reverse(all(g[v]));
    st = segtree(n);
    for (int i = 0; i < g[v].size(); i++) {
        for (int x : res[g[v][i]]) {
            ans[ord[x]] = min(ans[ord[x]], x - st.get(x, x));
        }
        for (int j = 0; j < res[g[v][i]].size(); j++) {
            st.upd(res[g[v][i]][j], n - 1, j + 1);
        }
    }

    res[v] = {pos[v]};
    for (int i = 0; i < g[v].size(); i++) {
        for (int x : res[g[v][i]]) res[v].push_back(x);
    }
    sort(all(res[v]));
}

void solve() {
    int q;
    cin >> n >> q;
    vector<int> p(n);
    g.resize(n);
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        g[p[i]].push_back(i);
    }
    vector<int> a(n), qr(q);
    cin >> a >> qr;
    for (int &x: qr) x--;

    pos.resize(n);
    {
        set<pair<int, int>> s;
        s.emplace(a[0], 0);
        while (!s.empty()) {
            int i = prev(s.end())->second;
            pos[i] = ord.size();
            s.erase(prev(s.end()));
            ord.push_back(i);
            for (int to : g[i]) s.emplace(a[to], to);
        }
    }

    ans = pos;
    dfs(0);

    for (int x : qr) cout << ans[x] << " ";
}

//5 5
//1 1 1 1
//1 2 3 4 5
//1 2 3 4 5

signed main() {
#ifndef LOCAL
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
#endif

    int t = 1;
//    cin >> t;
    while (t--) solve();
}