#include <bits/stdc++.h>
const int N = 200000;
struct Info {
  int one, zero;
};
bool operator<(const Info& a, const Info& b) {
  return 1LL * a.one * b.zero > 1LL * a.zero * b.one;
}
int n, p[N], par[N];
Info info[N];
int find(int u) {
  if (par[u] != u) {
    par[u] = find(par[u]);
  }
  return par[u];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d", p + i);
    p[i]--;
  }
  for (int i = 0, a; i < n; ++i) {
    scanf("%d", &a);
    info[i] = a == 1 ? Info{1, 0} : Info{0, 1};
    par[i] = i;
  }
  std::priority_queue<std::pair<Info, int>> q;
  for (int i = 1; i < n; ++i) {
    q.emplace(info[i], i);
  }
  long long result = 0;
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (find(u) != u) {
      continue;
    }
    par[u] = p[u];
    int pu = find(u);
    result += 1LL * info[pu].one * info[u].zero;
    info[pu].one += info[u].one;
    info[pu].zero += info[u].zero;
    if (pu != 0) {
      q.emplace(info[pu], pu);
    }
  }
  printf("%lld\n", result);
}
