#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
struct data
{
	int a0,a1,id;
	friend bool operator < (data a,data b){return 1ll*a.a1*b.a0==1ll*a.a0*b.a1?a.id<b.id:1ll*a.a1*b.a0<1ll*a.a0*b.a1;}
	friend data operator + (data a,data b){return data{a.a0+b.a0,a.a1+b.a1,a.id};}
}c[200020];
int n,p[200020],v[200020],f[200020];
long long ans;
set<data>s;
int find(int x)
{
	if(x!=f[x])return f[x]=find(f[x]);
	return x;
}
int main()
{
	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]);
		if(v[i]==0)c[i]=data{1,0,i};
		else c[i]=data{0,1,i};
		s.insert(c[i]);
		f[i]=i;
	}
	int x,y;
	while(s.size())
	{
		x=s.begin()->id;s.erase(s.begin());
		if(x==1)continue;
	//	printf("%d\n",x);
		y=find(p[x]);f[x]=y;
		s.erase(c[y]);
		ans+=1ll*c[y].a1*c[x].a0;
		c[y]=c[y]+c[x];
		s.insert(c[y]);
	}
	printf("%lld",ans);
	return 0;
}
