#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  long long solve(vector<int>& A, vector<int>& pars) {
    int n = A.size();
    vector<vector<int>> graph(n);
    for (int i = 0; i < n; ++i) {
      int p = pars[i];
      if (p >= 0) {
        graph[p].push_back(i);
      }
    }
    long long total = 0;
    for (auto x : A) {
      total += x;
    }
    const long long INF = 1LL << 60;
    vector<long long> dp(n + 1, 0);
    auto ok = [&](long long x) {
      fill(dp.begin(), dp.end(), 0LL);
      for (int i = n - 1; i >= 0; --i) {
        if (graph[i].empty()) {
          if (x < A[i]) {
            return false;
          }
          dp[i] = max(0LL, x - A[i]);
          continue;
        }
        for (auto v : graph[i]) {
          dp[i] += dp[v];
          dp[i] = min(dp[i], INF);
        }
        if (dp[i] < A[i]) {
          return false;
        }
        dp[i] -= A[i];
      }
      return dp[0] >= 0;
    };
    long long lo = 0, hi = total;
    while (lo < hi) {
      auto mi = (lo + hi) / 2;
      if (ok(mi)) {
        hi = mi;
      } else {
        lo = mi + 1;
      }
    }
    return lo;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int n;
  cin >> n;
  vector<int> pars(n, -1);
  for (int i = 1; i < n; ++i) {
    cin >> pars[i];
    --pars[i];
  }
  vector<int> A(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
  }
  cout << sol.solve(A, pars) << '\n';
  return 0;
}
