#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

using namespace std;

#define int long long
#define double long double

typedef tree<int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multi_set;

int inf = (int)1000 * 1000 * 1000 * 1000 * 1000 * 1000;

struct st //+=, sum
{
    vector <int> t;
    vector <int> p;

    void build(int n)
    {
        t.resize(4 * n, 0);
        p.resize(4 * n, 0);
    }

    void push(int v, int l, int r)
    {
        if (p[v] != 0)
        {
            p[v * 2 + 1] += p[v];
            p[v * 2 + 2] += p[v];
            int m = (l + r) / 2;
            t[v * 2 + 1] += (m - l + 1) * p[v];
            t[v * 2 + 2] += (r - m) * p[v];
            p[v] = 0;
        }
    }

    int get(int v, int l, int r, int ll, int rr)
    {
        if (ll > rr)
        {
            return 0;
        }
        if (l == ll && r == rr)
        {
            return t[v];
        }

        int m = (l + r) / 2;
        push(v, l, r);
        return get(v * 2 + 1, l, m, ll, min(m, rr)) +
               get(v * 2 + 2, m + 1, r, max(m + 1, ll), rr);
    }

    void update(int v, int l, int r, int ll, int rr, int x)
    {
        if (ll > rr)
        {
            return;
        }
        if (l == ll && r == rr)
        {
            t[v] += x * (r - l + 1);
            p[v] += x;
            return;
        }
        int m = (l + r) / 2;
        push(v, l, r);
        update(v * 2 + 1, l, m, ll, min(m, rr), x);
        update(v * 2 + 2, m + 1, r, max(m + 1, ll), rr, x);
        t[v] = t[v * 2 + 1] + t[v * 2 + 2];
    }
};

int mod = 1000 * 1000 * 1000 + 7;

int bin_pow(int a, int x)
{
    if (x == 0)
    {
        return 1;
    }
    if (x % 2 == 0)
    {
        return bin_pow((a * a) % mod, x / 2);
    }
    return (a * bin_pow((a * a) % mod, x / 2)) % mod;
}

int add(int a, int b)
{
    if (a + b >= mod)
    {
        return a + b - mod;
    }
    return a + b;
}

int umn(int a, int b)
{
    return (a * b) % mod;
}

int del(int a, int b)
{
    return umn(a, bin_pow(b, mod - 2));
}

vector <int> p;
vector <int> s;
vector <int> sz;
vector <int> h;
vector <bool> t;
vector <int> pp;

void dfs(int v, vector <bool> &used, vector <vector <int>> &g)
{
    used[v] = true;
    sz[v] = 1;
    for (auto u : g[v])
    {
        if (v == 1)
        {
            pp[u] = u;
        }
        else
        {
            pp[u] = pp[v];
        }
        h[u] = h[v] + 1;
        sz[v] += sz[u];
        dfs(u, used, g);
    }
}

void update(int v, vector <vector <int>> &g)
{
    if (!t[v])
    {
        return;
    }
    t[v] = false;
    for (auto u : g[v])
    {
        update(u, g);
    }
}

void solve()
{
    int n, q;
    cin >> n >> q;
    p.resize(n);
    p[0] = 0;
    for (int i = 1; i < n; i ++)
    {
        cin >> p[i];
        p[i] --;
    }
    s.resize(n);
    for (int i = 0; i < n; i ++)
    {
        cin >> s[i];
    }

    vector <vector <int>> g(n);
    for (int i = 1; i < n; i ++)
    {
        g[p[i]].push_back(i);
    }

    sz.resize(n);
    h.resize(n);
    h[0] = 0;
    vector <bool> used(n, false);
    pp.resize(n);
    dfs(0, used, g);

    t.resize(n, true);

    multiset <int> ss;
    int sum = 0;
    for (auto v : g[0])
    {
        ss.insert(sz[v]);
        sum += sz[v];
    }

    vector <int> dp(n + 1);
    vector <int> f(n + 1);
    for (int i = 0; i < n; i ++)
    {
        f[s[i]] = i;
    }

    for (int i = 1; i <= n; i ++)
    {
        if (i != 1)
        {
            //i - 1
            int v = f[i - 1];
            if (v != 0)
            {
                int u = pp[v];
                ss.erase(ss.find(sz[u]));
                sum -= sz[u];
                if (v != u)
                {
                    sz[u] -= sz[v];
                    ss.insert(sz[u]);
                    sum += sz[u];
                }
                update(v, g);
            }
        }
        if (f[i] != 0)
        {
            int delta = 0;
            auto k = ss.begin();
            if (k != ss.end())
            {
                if (*k == sz[pp[f[i]]])
                {
                    k ++;
                }
                if (k != ss.end())
                {
                    delta = *k;
                }
            }
            dp[i] = sum + h[f[i]] - sz[pp[f[i]]] - delta;
        }
    }

    for (int i = 0; i < q; i ++)
    {
        int v;
        cin >> v;
        v --;
        if (v == 0)
        {
            cout << 0 << " ";
        }
        else
        {
            cout << dp[s[v]] << " ";
        }
    }
}

signed main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

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