#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
typedef long long ll;
typedef long double ld;
const int MAXN = 200005;
int par[MAXN], P[MAXN], V[MAXN];
ll num0[MAXN], num1[MAXN], val[MAXN];
int root(int a) {
	if (par[a] == a) return a;
	return par[a] = root(par[a]);
}
struct cmp {
	bool operator()(int a, int b) {
		ll va = num0[a] * num1[b], vb = num0[b] * num1[a];
		if (va != vb) return va > vb;
		return a < b;
	}
};
int main() {
	int N;
	scanf("%d", &N);
	for (int i = 2; i <= N; ++i) scanf("%d", &P[i]);
	for (int i = 1; i <= N; ++i) scanf("%d", &V[i]);
	for (int i = 1; i <= N; ++i) {
		par[i] = i;
		if (V[i] == 1) ++num1[i];
		else ++num0[i];
	}
	set<int, cmp> S;
	for (int i = 2; i <= N; ++i) {
		S.insert(i);
	}
	while (!S.empty()) {
		int x = *S.begin();
		S.erase(S.begin());
		int y = root(P[x]);
		S.erase(y);
		par[x] = y;
		val[y] += val[x] + num1[y] * num0[x];
		num0[y] += num0[x];
		num1[y] += num1[x];
		if (y != 1) S.insert(y);
	}
	printf("%lld\n", val[1]);
}
