#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    p[0] = 0;
    vector<vector<int>> gr(n);
    map<pair<int, int>, bool> my_map;
    my_map[{0, 0}] = true;
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
        gr[p[i]].push_back(i);
        int v = i;
        while (true) {
            my_map[{v, i}] = true;
            if (v == 0) {
                break;
            }
            v = p[v];
        }
    }
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    set<pair<int, int>> ans;
    ans.insert({-s[0], 0});
    vector<int> vec;
    while (!ans.empty()) {
        pair<int, int> c = *ans.begin();
        ans.erase(c);
        vec.push_back(c.second);
        cout << c.second << endl;
        for (auto x : gr[c.second]) {
            ans.insert({-s[x], x});
        }
    }
    set<pair<int, int>> st;
    vector<int> answ(n);
    for (int i = 0; i < n; i++) {
        st.insert({0, i});
    }
    vector<int> answer(n);
    for (int i = 0; i < n; i++) {
        int v = vec[i];
        while (true) {
            st.erase({answ[v], v});
            answ[v]--;
            st.insert({answ[v], v});
            if (v == 0) {
                break;
            }
            v = p[v];
        }
        int pos = i;
        auto it = st.begin();
        while (true) {
            if (!my_map[{(*it).second, vec[i]}]) {
                pos += (*it).first;
                break;
            }
            it++;
            if (it == st.end()) {
                break;
            }
        }
        answer[vec[i]] = pos;
    }
    for (int i = 0; i < q; i++) {
        int v;
        cin >> v;
        v--;
        cout << answer[v] << " ";
    }
}
