#include <bits/stdc++.h>
using namespace std;

struct Node {
	int x, y, id;
	long long sum;
	bool operator < (const Node &A) const {
		return 1ll * y * A.x < 1ll * A.y * x || 1ll * y * A.x == 1ll * A.y * x && id < A.id;
	}
	Node operator += (const Node &A) {
		sum += 1ll * y * A.x + A.sum, x += A.x, y += A.y;
		return *this;
	}
};

set <Node> S;
int fa[200010];
Node a[200010];
int par[200010];

int find(int x) {
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main () {
	int n; scanf("%d", &n);
	for (int i = 2; i <= n; i++) {
		scanf("%d", &par[i]);
	}
	for (int i = 1; i <= n; i++) {
		fa[i] = i;
		int x; scanf("%d", &x);
		if (x) a[i].x = 0, a[i].y = 1, a[i].id = i, a[i].sum = 0;
		else a[i].x = 1, a[i].y = 0, a[i].id = i, a[i].sum = 0;
		if (i != 1) S.insert(a[i]);
	}
	while (S.size()) {
		int x = S.begin()->id; S.erase(S.begin());
		int p = find(par[x]);
		if (p != 1) S.erase(a[p]);
		a[p] += a[x], fa[x] = p;
		if (p != 1) S.insert(a[p]);
	}
	printf("%lld\n", a[1].sum);
	return 0;
}
