#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct node {
  int c[2], fa, id;
  bool operator<(const node &x) const {
    return 1LL * c[0] * x.c[1] < 1LL * c[1] * x.c[0];
  }
};
node a[N];
priority_queue<node> q;
int father[N], n, c[2][N];
inline int read() {
  int z = 0, base = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') c = getchar();
  while (isdigit(c)) z = z * 10 + c - '0', c = getchar();
  return z * base;
}
inline int find(int x) {
  return father[x] == x ? x : father[x] = find(father[x]);
}
inline void uni(int x, int y) {
  int f1 = find(x), f2 = find(y);
  if (f1 != f2) father[f1] = f2;
}
inline void print() {
  int b[10], cnt = 0;
  while (!q.empty()) {
    b[++cnt] = q.top().id;
    q.pop();
  }
  for (register int i = 1; i <= cnt; ++i) printf("%d ", b[i]), q.push(a[b[i]]);
  printf("\n");
}
int main() {
  int x;
  n = read();
  for (register int i = 1; i <= n; ++i) father[i] = i, a[i].id = i;
  for (register int i = 2; i <= n; ++i) a[i].fa = read();
  for (register int i = 1; i <= n; ++i) x = read(), a[i].c[x] = 1, c[x][i]++;
  for (register int i = 2; i <= n; ++i) q.push(a[i]);
  long long ans = 0;
  while (!q.empty()) {
    int cur = find(q.top().id);
    q.pop();
    if ((c[0][cur] == a[cur].c[0] || c[1][cur] == a[cur].c[1]) && cur != 1) {
      int f = find(a[cur].fa);
      ans += a[f].c[1] * a[cur].c[0];
      a[f].c[1] += a[cur].c[1], a[f].c[0] += a[cur].c[0];
      c[1][f] = a[f].c[1], c[0][f] = a[f].c[0];
      uni(cur, f);
      if (f != 1) q.push(a[f]);
    }
  }
  printf("%lld", ans);
  return 0;
}
