#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 998244353;
const int MAXN = 600005;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
int cnt[MAXN][2], fa[MAXN], f[MAXN];
struct heapnode {
  int x, y, id;
  bool operator<(const heapnode &a) const {
    return 1ll * x * a.y < 1ll * y * a.x;
  }
};
priority_queue<heapnode> heap;
int find(int x) { return f[x] == x ? f[x] : f[x] = find(f[x]); }
int main() {
  int n = read();
  for (int i = 2; i <= n; i++) fa[i] = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    cnt[i][x]++;
    f[i] = i;
  }
  for (int i = 2; i <= n; i++) heap.push((heapnode){cnt[i][0], cnt[i][1], i});
  long long ans = 0;
  while (!heap.empty()) {
    int u = find(heap.top().id), x = heap.top().x, y = heap.top().y;
    heap.pop();
    if (cnt[u][0] == x && cnt[u][1] == y) {
      int v = find(fa[u]);
      ans += 1ll * cnt[v][1] * cnt[u][0];
      cnt[v][0] += cnt[u][0];
      cnt[v][1] += cnt[u][1];
      f[u] = v;
      if (v != 1) heap.push((heapnode){cnt[v][0], cnt[v][1], v});
    }
  }
  printf("%lld\n", ans);
  return 0;
}
