#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

struct DSU
{
	int fa[MAXN];
	inline void init(int n){ for(int i=1; i<=n; ++i) fa[i] = i;}
	int find(int u){ return fa[u] == u? u: fa[u] = find(fa[u]);}
	inline void connect(int u,int v){ fa[find(u)] = find(v);}
}dsu;

int pre[MAXN], val[MAXN];

int f[MAXN], g[MAXN];

struct cmp{ inline bool operator () (int x,int y) const; };

inline bool cmp::operator () (int x,int y) const
{
	return make_pair((ll)g[x] * f[y], x) < make_pair((ll)g[y] * f[x], y);
}

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=2; i<=n; ++i) scanf("%d",&pre[i]);
	for(int i=1; i<=n; ++i) scanf("%d",&val[i]);
	
	for(int i=1; i<=n; ++i)
	{
		if(val[i]) g[i] = 1;
		else f[i] = 1;
	}
	
	set<int,cmp> t;
	for(int i=2; i<=n; ++i)
		t.insert(i);
	
	dsu.init(n);
	
	ll ans = 0;
	while(!t.empty())
	{
		int u = *t.begin(), fa = dsu.find(pre[u]);
		t.erase(t.begin());
		if(fa != 1) t.erase(fa);
		
		ans += (ll)g[fa] * f[u];
		
		f[fa] += f[u];
		g[fa] += g[u];
		dsu.connect(u, fa);
		
		if(fa != 1) t.insert(fa);
	}
	
	printf("%lld",ans);
	return 0;
}