#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 300000;

int n;
int fa[N], c[N][2], pi[N]; LL res;
struct cp
{
    int operator () (int a, int b)
    {
        if (1ll * c[a][0] * c[b][1] != 1ll * c[b][0] * c[a][1])
            return (1ll * c[a][0] * c[b][1] > 1ll * c[b][0] * c[a][1]);
        return a < b;
    }
};
set <int, cp> S;
int get_f(int t)
{
    if (fa[t] == t) return t;
    else return fa[t] = get_f(fa[t]);
}
int main()
{
    scanf("%d", &n);
    for (int i = 2; i <= n; ++ i)
        scanf("%d", &pi[i]);
    for (int i = 1; i <= n; ++ i)
        fa[i] = i;
    for (int i = 1; i <= n; ++ i)
    {
        int v;
        scanf("%d", &v);
        c[i][v] = 1;
        S.insert(i);
    }
    while (!S.empty())
    {
        auto it = S.begin();
        int t = *it; S.erase(it);
        int p = get_f(pi[t]); fa[t] = p;
        if (p) S.erase(p);
        res += 1ll * c[p][1] * c[t][0];
        c[p][0] += c[t][0];
        c[p][1] += c[t][1];
        if (p) S.insert(p);
    }
    printf("%lld\n", res);
}
