#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
long long ans;
int n, p[maxn + 10], fa[maxn + 10];
int sz[maxn + 10][2];

struct data {
	int p, x, y;
	bool operator < (const data &t) const {
		return 1ll * x * t.y < 1ll * t.x * y;
	}
};
priority_queue<data> pq;

int getf(int p) {
	return fa[p] == p ? p : fa[p] = getf(fa[p]);
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; ++i) scanf("%d", &p[i]);
	for (int i = 1; i <= n; ++i) {
		int x; scanf("%d", &x);
		++sz[i][x]; fa[i] = i;
	}
	for (int i = 2; i <= n; ++i)
		pq.push((data){i, sz[i][0], sz[i][1]});
	while (!pq.empty()) {
		data e = pq.top(); pq.pop();
		if (fa[e.p] == e.p && e.x == sz[e.p][0] && e.y == sz[e.p][1]) {
			int f = getf(p[e.p]);
			ans += 1ll * sz[f][1] * sz[e.p][0];
			sz[f][0] += sz[e.p][0]; sz[f][1] += sz[e.p][1];
			fa[e.p] = f;
			if (f != 1) pq.push((data){f, sz[f][0], sz[f][1]});
		}
	}
	printf("%lld", ans);
}
