#include <bits/stdc++.h>
using namespace std;
void pr(long long x, bool fl = false) {
  cout << x << endl;
  if (fl) exit(0);
}
void pr(long long x, long long y, bool fl = false) {
  cout << x << " " << y << endl;
  if (fl) exit(0);
}
const long long mod = 998244353;
const long long inf = LLONG_MAX;
const long long minf = LLONG_MIN;
const long long maxn = 1000000;
const long long maxc = 26;
long long c, xx, y, z, n, m, q, k, l, r, u, v, w, tmp, nxt, rt, cur, dis;
long long ans, val, flag, cnt;
long long a[maxn + 5], p[maxn + 5];
vector<long long> e[maxn + 5];
long long dfs(long long rt) {
  long long d = 0;
  if (e[rt].empty()) {
    if (k < a[rt]) flag = false;
    return a[rt] - k;
  }
  for (long long i = 0; i <= e[rt].size() - 1; i++) {
    long long nxt = e[rt][i];
    d += dfs(nxt);
    if (d < -val and d < -10000000000000000) return -val;
  }
  if (d + a[rt] > 0) flag = false;
  return d + a[rt];
}
bool check(long long nowx) {
  k = nowx;
  flag = true;
  dfs(1);
  return flag;
}
long long read() {
  long long x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
signed main() {
  n = read();
  for (long long i = 2; i <= n; i++) p[i] = read(), e[p[i]].push_back(i);
  for (long long i = 1; i <= n; i++) a[i] = read(), val += a[i];
  long long l = 0, r = val;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  if (check(r))
    cout << r << endl;
  else
    cout << r + 1 << endl;
}
