#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int t;
    cin >> t;
    t--;
    g[t].push_back(i + 1);
    g[i + 1].push_back(t);
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> dp1(n);
  vector<long long> dp2(n);
  vector<long long> dp3(n);
  function<void(int, int)> dfs = [&](int v, int pred) {
    for (int to : g[v]) {
      if (to ^ pred) dfs(to, v);
    }
    if (g[v].size() == 1 && v != 0) {
      dp1[v] = a[v];
      a[v] = 0;
      dp2[v] = 1;
    }
    for (int to : g[v]) {
      if (to ^ pred) {
        dp1[v] = max(dp1[v], dp1[to]);
        dp2[v] += dp2[to];
      }
    }
    for (int to : g[v]) {
      if (to ^ pred) {
        dp3[v] += dp3[to] + ((dp1[v] - dp1[to]) * dp2[to]);
      }
    }
    long long t = min(dp3[v], (long long)a[v]);
    dp3[v] -= t;
    a[v] -= t;
    long long add = a[v] / dp2[v];
    dp1[v] += add;
    a[v] %= dp2[v];
    if (a[v] > 0) {
      dp1[v]++;
      dp3[v] += dp2[v] - a[v];
    }
  };
  dfs(0, 0);
  cout << dp1[0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q = 1;
  for (; q > 0; q--) {
    solve();
  }
}
