#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 7;
template <class T>
T rd() {
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  T x = 0;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return f ? x : -x;
}
int n;
struct pii {
  int a[2];
  int id;
  inline bool operator<(const pii &v) const {
    if (a[0] == 0) return true;
    if (v.a[0] == 0) return false;
    return (long long)a[1] * v.a[0] > (long long)a[0] * v.a[1];
  }
  inline bool operator!=(const pii &v) const {
    return a[0] != v.a[0] || a[1] != v.a[1];
  }
} a[maxN];
int pre[maxN];
int dsu[maxN];
list<int> lis[maxN];
priority_queue<pii> q;
int find(int x) { return dsu[x] != x ? dsu[x] = find(dsu[x]) : x; }
int main() {
  n = rd<int>();
  for (int i = (2), _ = (n); i <= _; ++i) pre[i] = rd<int>();
  for (int i = (1), _ = (n); i <= _; ++i) {
    int x = rd<int>();
    if (x == 1)
      ++a[i].a[1];
    else
      ++a[i].a[0];
    a[i].id = i;
    lis[i].push_back(x);
    q.push(a[i]);
    dsu[i] = i;
  }
  while (!q.empty()) {
    int x = q.top().id;
    if (a[x] != q.top()) {
      q.pop();
      continue;
    }
    q.pop();
    int y = find(pre[x]);
    lis[y].splice(lis[y].end(), lis[x]);
    a[y].a[0] += a[x].a[0];
    a[y].a[1] += a[x].a[1];
    if (y) q.push(a[y]);
    dsu[x] = pre[x];
  }
  long long cnt = 0, res = 0;
  for (list<int>::reverse_iterator it = lis[0].rbegin(); it != lis[0].rend();
       ++it) {
    if (*it == 0)
      ++cnt;
    else
      res += cnt;
  }
  printf("%lld\n", res);
  return 0;
}
