#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
struct Tuple {
  int v, c0, c1;
  bool operator<(const Tuple &r) const { return c0 * r.c1 < r.c0 * c1; }
};
priority_queue<Tuple> q;
int n, col[N], ufP[N], trP[N], c0[N], c1[N];
vector<int> g[N];
long long ans;
int find(int x) { return ufP[x] == x ? x : ufP[x] = find(ufP[x]); }
int main(int argc, char *argv[]) {
  scanf("%d", &n);
  for (int i = 2; i <= (n); ++i) {
    scanf("%d", trP + i);
    g[trP[i]].push_back(i);
  }
  for (int i = 1; i <= (n); ++i) {
    scanf("%d", col + i);
    c0[i] = col[i] == 0;
    c1[i] = col[i] == 1;
    ufP[i] = i;
    if (i > 1) q.push((Tuple){i, c0[i], c1[i]});
  }
  for (int k = 1; k <= (n - 1); ++k) {
    Tuple t;
    for (t = q.top(); t.c0 != c0[t.v] || t.c1 != c1[t.v]; q.pop(), t = q.top())
      ;
    assert(find(t.v) == t.v);
    int f = find(trP[t.v]);
    ans += 1ll * c1[f] * c0[t.v];
    c0[f] += c0[t.v];
    c1[f] += c1[t.v];
    if (f > 1) q.push((Tuple){f, c0[f], c1[f]});
    ufP[t.v] = f;
    c0[t.v] = c1[t.v] = -1;
  }
  printf("%lld\n", ans);
  return 0;
}
