#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
const double DINF=1e40;
const double EPS=1e-6;
int n;
int pre[N];
int col[N];
int bel[N];
int c[N][2];
struct Data{
	int u;
	double x;
	Data(){}
	Data(int _u,double _x):u(_u),x(_x){}
	friend bool operator < (const Data &a,const Data &b){
		return a.x<b.x;
	}
};
priority_queue<Data> q;
bool use[N];
void readData(){
	scanf("%d",&n);
	for(int v=2;v<=n;v++)
		scanf("%d",&pre[v]);
	for(int i=1;i<=n;i++) 
		scanf("%d",&col[i]);
}
int findBel(int u){
	return bel[u]==u?u:(bel[u]=findBel(bel[u]));
}
double getVal(int u){
	return c[u][1]?(1.0*c[u][0]/c[u][1]):DINF;
}
void init(){
	for(int i=1;i<=n;i++){
		bel[i]=i;
		c[i][0]=(col[i]==0);
		c[i][1]=(col[i]==1);
		if(i>1)
			q.push(Data(i,getVal(i)));
	}
}
bool legal(int u,double now){
	return fabs(now-getVal(u))<=EPS;
}
void solve(){
	ll ans=0;
	Data cur;
	int u,fp;
	while(!q.empty()){
		cur=q.top();
		q.pop();
		u=cur.u;
		if(use[u]||!legal(u,cur.x))
			continue;
		use[u]=true;
		fp=findBel(pre[u]);
		ans+=1ll*c[fp][1]*c[u][0];
		c[fp][0]+=c[u][0];
		c[fp][1]+=c[u][1];
		if(fp!=1)
			q.push(Data(fp,getVal(fp)));
		bel[u]=fp;
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}
