#include <bits/stdc++.h>
using namespace std;
namespace SHENZHEBEI {
inline char gc() { return getchar(); }
inline long long read() {
  long long x = 0, fa = 1;
  char ch = gc();
  for (; !isdigit(ch); ch = gc())
    if (ch == '-') fa = -1;
  for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch;
  return x * fa;
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(long long x) {
  write(x);
  puts("");
}
}  // namespace SHENZHEBEI
using namespace SHENZHEBEI;
const long long N = 1000010;
long long n, tot, a[N], dfn[N], head[N], nxt[N], vet[N], pre[N], fa[N], q[N],
    w[N], ans;
struct dt {
  long long a, b, c;
} lbc[N];
bool operator<(dt a, dt b) {
  return a.a * b.b == b.a * a.b ? (a.a > b.a) : (a.a * b.b > b.a * a.b);
}
bool operator!=(dt a, dt b) {
  return (a.a != b.a) || (a.b != b.b) || (a.c != b.c);
}
priority_queue<dt> Q;
void link(long long x, long long y) {
  ++dfn[y];
  pre[y] = x;
  nxt[++tot] = head[x];
  head[x] = tot;
  vet[tot] = y;
}
long long find(long long x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
bool pd() {
  long long he = 0, ta = 1;
  for (; he ^ ta;) {
    long long x = q[++he];
    for (long long i = head[x]; i; i = nxt[i])
      if (!--dfn[vet[i]]) q[++ta] = vet[i];
  }
  for (long long i = 1; i <= n; ++i)
    if (dfn[i]) return 0;
  return 1;
}
int main() {
  n = read();
  for (long long i = 2; i <= n; ++i) pre[i] = read();
  for (long long i = 1; i <= n; ++i) w[i] = read();
  for (long long i = 1; i <= n; ++i)
    Q.push(lbc[i] = (dt){w[i], 1, i}), fa[i] = i;
  for (; !Q.empty();) {
    dt x = Q.top();
    Q.pop();
    if (x != lbc[find(x.c)]) continue;
    ans += (x.b - x.a) * lbc[find(pre[x.c])].a;
    if (!find(pre[x.c]))
      fa[x.c] = 0, lbc[0].b += x.b, lbc[0].a += x.a;
    else {
      fa[x.c] = find(pre[x.c]);
      lbc[fa[x.c]].a += x.a;
      lbc[fa[x.c]].b += x.b;
      Q.push(lbc[fa[x.c]]);
    }
  }
  writeln(ans);
}
