#include <bits/stdc++.h>
using namespace std;
int n;
int p[200005], v[200005], c1[200005], c0[200005];
int fa[200005];
struct Node {
  int c0, c1, id;
};
bool operator<(const Node &X, const Node &Y) {
  return X.c1 * Y.c0 < X.c0 * Y.c1 ||
         (X.c1 * Y.c0 == X.c0 * Y.c1 && X.id < Y.id);
}
int getfather(int x) {
  if (fa[x] == x) {
    return x;
  } else {
    return fa[x] = getfather(fa[x]);
  }
}
long long ans;
set<Node> s;
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    cin >> p[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    if (v[i] == 1) {
      c1[i] = 1;
      c0[i] = 0;
    } else {
      c1[i] = 0;
      c0[i] = 1;
    }
    fa[i] = i;
  }
  for (int i = 2; i <= n; i++) {
    s.insert({c0[i], c1[i], i});
  }
  while (s.size()) {
    Node u = *s.begin();
    s.erase(s.begin());
    int x = u.id;
    int y = fa[x] = getfather(p[x]);
    ans += (long long)c1[y] * (long long)c0[x];
    if (y != 1) {
      s.erase({c0[y], c1[y], y});
    }
    c0[y] += c0[x];
    c1[y] += c1[x];
    if (y != 1) {
      s.insert({c0[y], c1[y], y});
    }
  }
  cout << ans;
  return 0;
}
