// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define maxn 1000009
#define LL long long
#define FK fa[cnt]=cnt,fa[l]=cnt,fa[find(v.z)]=cnt
#define ST dad[cnt]=dad[l],dad[v.z]=cnt,pt[cnt]=tmp,st.insert(tmp)
#define EP st.empty()
#define BEGIN {
#define END }
using namespace std;
struct node{
  LL x;int y,z;
  inline bool operator < (const node &h) const{
    if(x*h.y!=h.x*y) return x*h.y<h.x*y;
    else return z<h.z;
  }
}pt[maxn];
int head[maxn],edge=0,fa[maxn],dad[maxn],sz[maxn],w[maxn];
set<node>st;
int n;LL ans=0,sum[maxn];
int find(int x){if(fa[x]!=x) fa[x]=find(fa[x]);return fa[x];}
inline void work() BEGIN
  int cnt=n;LL Ans=0;
  while(!EP) BEGIN
    node v=*st.begin();st.erase(v);
    int l=find(dad[v.z]); if(!l) continue;
    Ans+=(v.y-v.x)*pt[l].x;
    st.erase(pt[l]);
    node tmp=v;
    tmp.x+=pt[l].x,tmp.y+=pt[l].y,tmp.z=++cnt;
    FK;ST;
  END printf("%lld",Ans);
END
int main(){
  scanf("%d",&n);
  for(int i=2;i<=n;i++)
    scanf("%d",&dad[i]);
  for(int i=1;i<=n;i++) scanf("%d",w+i);
  for(int i=1,x;i<=n;i++)
    pt[i]=(node){w[i],1,i},st.insert(pt[i]),fa[i]=i;
  work();
  return 0;
}
