#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=200005;
int v[Maxn],prt[Maxn],fa[Maxn],cnt[Maxn][2],tag[Maxn];
ll ans;
struct node{
    int cnt[2],id,tag;
    node(int cnt0,int cnt1,int _id,int _tag){
        cnt[0]=cnt0;cnt[1]=cnt1;id=_id;tag=_tag;
    }
    bool operator<(const node&rhs)const{
        return 1ll*cnt[0]*rhs.cnt[1]<1ll*cnt[1]*rhs.cnt[0];
    }
};
inline int Getfa(int x){return fa[x]=(fa[x]==x?x:Getfa(fa[x]));}
int main(){
    int n;scanf("%d",&n);
    for(int i=2;i<=n;i++)scanf("%d",&prt[i]);
    for(int i=1;i<=n;i++)scanf("%d",&v[i]),fa[i]=i,cnt[i][v[i]]++;
    priority_queue<node>Q;
    for(int i=1;i<=n;i++)Q.push(node(v[i]==0,v[i]==1,i,0));
    while(Q.size()){
        static int ts;
        node o=Q.top();Q.pop();
        int x=Getfa(o.id),y=Getfa(prt[x]);
        if(x==1||o.tag!=tag[x])continue;
        ans+=1ll*cnt[y][1]*cnt[x][0];
        cnt[y][0]+=cnt[x][0];
        cnt[y][1]+=cnt[x][1];
        fa[x]=y;tag[y]=++ts;
        Q.push(node(cnt[y][0],cnt[y][1],y,tag[y]));
    }
    cout<<ans<<"\n";
    return 0;
}