#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int avai = a[src];
    int req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e15;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int avai = a[src];
    int req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 5e13;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int avai = a[src];
    int req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e12;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int avai = a[src];
    int req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e18;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

__int128 dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    __int128 avai = a[src];
    __int128 req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e18;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int128 avai = a[src];
    int128 req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e18;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

#define rep(i,a,b) for(int i = a; i < b; i++)

const int N = 2e5 + 5;

vector<int> v[N], a(N);
bool ok;

int dfs(int src, int mx) {
    //Check on each step whether req - available >= 0
    if(!ok) return 0;
    int128 avai = a[src];
    int128 req = 0;
    for(auto i : v[src]) {
        req += dfs(i, mx);
    }
    if(v[src].size() == 0) {
        if(mx - avai < 0) ok = false;
        return mx - avai;
    }
    if(req - avai < 0) ok = false;
    return req - avai;
}

int32_t main()
{
    IOS
    int n;
    cin >> n;
    rep(i,2,n+1) {
        int p;
        cin >> p;
        v[p].push_back(i);
    }
    rep(i,1,n + 1) {
        cin >> a[i];
    }
    int lo = 0, hi = 1e13;
    ok = true;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        ok = true;
        dfs(1, mid);
        if(ok) {
            hi = mid - 1;
        } else lo = mid + 1;
    }
    cout << lo << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],ans,s[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod)
{
    use[nod]=1;
    if(muchii[nod].size()==0)
    {
        s[nod]=val[nod];
        nr[nod]=1;
        ans=max(ans,val[nod]);
        return;
    }
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i);
            s[nod]+=s[i];
            nr[nod]+=nr[i];
        }
    s[nod]+=val[nod];
    ll x=s[nod]/nr[nod]+(s[nod]%nr[nod]!=0);
    ans=max(ans,x);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
        cin>>val[i];
    dfs(1);
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        return;
    }
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(dp[i]);
            maxim=max(maxim,dp[i]);
        }
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll nr=0;
        bool ok=1;
        for(auto i:q)
        {
            if(i<=mij)
                nr+=(mij-i);
            else
                ok=0;
        }
        if(nr>=val[nod]&&ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=maxim+val[nod];
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        for(auto i:q)
        {
            if(i<=mij)
                num+=(dp[i]*nr[i]-sum[i])+(mij-dp[i])*nr[i];
            if(i>mij)
                ok=0;
        }
        if(num<val[nod])
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        return;
    }
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(dp[i]);
            maxim=max(maxim,dp[i]);
        }
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=maxim+val[nod];
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll nr=0;
        for(auto i:q)
            if(i<mij)
                nr+=(mij-i);
        if(nr>=val[nod])
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001];
vector<ll> muchii[400001];
vector<ll> q;
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    val[nod]+=val[parent];
    if(muchii[nod].size()==0)
        q.push_back(nod);
    for(auto i:muchii[nod])
        if(!use[i])
            dfs(i,nod);
}
bool ok(ll x)
{
    ll toput=suma;
    for(auto nod:q)
    {
        ll l=init[nod];
        ll r=val[nod];
        if(l>x)
            return 0;
        if(r<=x)
            toput-=r;
        else
            toput-=x;
    }
    if(toput<=0)
        return 1;
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    ll maxim=0;
    for(auto i:q)
        maxim=max(maxim,val[i]);
    ll ans=maxim;
    ll st=0;
    ll dr=maxim;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        if(ok(mij))
        {
            ans=min(ans,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    ll st=0;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        for(auto i:q)
        {
            if(dp[i]<=mij)
                num+=(dp[i]*nr[i]-sum[i])+(mij-dp[i])*nr[i];
            if(dp[i]>mij)
                ok=0;
        }
        if(num<val[nod])
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    ll st=maxim;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        if(sum[nod]<=mij*nr[nod]&&mij>=maxim)
            ok=1;
        else
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
        }
    nr[nod]=q.size();
    sum[nod]=s+val[nod];
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=maxim+val[nod]*2;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        for(auto i:q)
        {
            if(i<=mij)
                num+=(dp[i]*nr[i]-sum[i])+(mij-dp[i])*nr[i];
            if(i>mij)
                ok=0;
        }
        if(num<val[nod])
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=maxim+val[nod]*2;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        for(auto i:q)
        {
            if(i<=mij)
                num+=(dp[i]*nr[i]-sum[i])+(mij-dp[i])*nr[i];
            if(i>mij)
                ok=0;
        }
        if(num<val[nod])
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    ll st=maxim;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        if(sum[nod]<=mij*nr[nod])
            ok=1;
        else
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001],sum[400001],nr[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        sum[nod]=val[nod];
        nr[nod]=1;
        return;
    }
    ll s=0,snr=0;
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(i);
            maxim=max(maxim,dp[i]);
            s+=sum[i];
            snr+=nr[i];
        }
    nr[nod]=snr;
    sum[nod]=s+val[nod];
    ll st=0;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll num=0;
        bool ok=1;
        for(auto i:q)
        {
            if(dp[i]<=mij)
            {
                num+=(dp[i]*nr[i]-sum[i]);
                if(mij!=dp[i])
                    num+=(mij-dp[i]-1)*nr[i]+1;
            }
            if(dp[i]>mij)
                ok=0;
        }
        if(num<val[nod])
            ok=0;
        if(ok)
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
//#pragma GCC optimize("O3")
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n,val[400001],suma,init[400001],dp[400001];
vector<ll> muchii[400001];
bool use[400001];
void dfs(ll nod,ll parent)
{
    use[nod]=1;
    vector<ll> q;
    ll maxim=0;
    if(muchii[nod].size()==0)
    {
        dp[nod]=val[nod];
        return;
    }
    for(auto i:muchii[nod])
        if(!use[i])
        {
            dfs(i,nod);
            q.push_back(dp[i]);
            maxim=max(maxim,dp[i]);
        }
    //sort(q.begin(),q.end());
    ll st=maxim;
    ll dr=suma;
    ll valmin=dr+1;
    while(st<=dr)
    {
        ll mij=(st+dr)/2;
        ll nr=0;
        for(auto i:q)
            if(i<mij)
                nr+=(mij-i);
        if(nr>=val[nod])
        {
            valmin=min(valmin,mij);
            dr=mij-1;
        }
        else
            st=mij+1;
    }
    dp[nod]=valmin;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        ll x;
        cin>>x;
        muchii[x].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>val[i];
        init[i]=val[i];
        suma+=val[i];
    }
    dfs(1,0);
    cout<<dp[1];
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll sob[MAXN];

void dfs(ll v, ll m){
	for(auto i:g[v])dfs(i,m);
	sob[v]=-a[v];
	if(SZ(g[v])==0)sob[v]+=m;
	for(auto i:g[v])sob[v]+=sob[i];
}

bool can(ll m){
	mset(sob,0);
	dfs(0,m);
	fore(i,0,n)if(sob[i]<0)return false;
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	ll l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<int,ll>> sob;

ll tot[MAXN];

//ll db=0;

bool can(ll m){
	//if(db)cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.fst<i&&j.snd){
				//if(db)cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//if(db)cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//if(db)cout<<"0\n";
			return false;
		}
	}
	//if(db)cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<int,ll>> sob;

ll tot[MAXN];

//ll db=0;

bool can(ll m){
	//if(db)cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.fst<i&&j.snd){
				//if(db)cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//if(db)cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//if(db)cout<<"0\n";
			return false;
		}
	}
	//if(db)cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e18;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll s[MAXN],c[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	s[v]=a[v];
	if(SZ(g[v])==0)c[v]=1;
	for(auto i:g[v])s[v]+=s[i],c[v]+=c[i];
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	dfs(0);
	ll res=0;
	fore(i,0,n){
		res=max(res,(s[i]+c[i]-1)/c[i]);
	}
	cout<<res<<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll s[MAXN],c[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	s[v]=a[v];
	if(SZ(g[v])==0)c[v]=1;
	for(auto i:g[v])s[v]+=a[i],c[v]+=c[i];
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	dfs(0);
	ll res=0;
	fore(i,0,n){
		res=max(res,(s[i]+c[i]-1)/c[i]);
	}
	cout<<res<<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll INF=1e18;
// Min cut: nodes with dist>=0 vs nodes with dist<0
// Matching MVC: left nodes with dist<0 + right nodes with dist>0
struct Dinic{
	int nodes,src,dst;
	vector<int> dist,q,work;
	struct edge {int to,rev;ll f,cap;};
	vector<vector<edge>> g;
	Dinic(int x):nodes(x),g(x),dist(x),q(x),work(x){}
	void add_edge(int s, int t, ll cap){
		g[s].pb((edge){t,SZ(g[t]),0,cap});
		g[t].pb((edge){s,SZ(g[s])-1,0,0});
	}
	bool dinic_bfs(){
		fill(ALL(dist),-1);dist[src]=0;
		int qt=0;q[qt++]=src;
		for(int qh=0;qh<qt;qh++){
			int u=q[qh];
			fore(i,0,SZ(g[u])){
				edge &e=g[u][i];int v=g[u][i].to;
				if(dist[v]<0&&e.f<e.cap)dist[v]=dist[u]+1,q[qt++]=v;
			}
		}
		return dist[dst]>=0;
	}
	ll dinic_dfs(int u, ll f){
		if(u==dst)return f;
		for(int &i=work[u];i<SZ(g[u]);i++){
			edge &e=g[u][i];
			if(e.cap<=e.f)continue;
			int v=e.to;
			if(dist[v]==dist[u]+1){
				ll df=dinic_dfs(v,min(f,e.cap-e.f));
				if(df>0){e.f+=df;g[v][e.rev].f-=df;return df;}
			}
		}
		return 0;
	}
	ll max_flow(int _src, int _dst){
		src=_src;dst=_dst;
		ll result=0;
		while(dinic_bfs()){
			fill(ALL(work),0);
			while(ll delta=dinic_dfs(src,INF))result+=delta;
		}
		return result;
	}
};

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n,sum=0;

bool can(ll m){
	Dinic d(n+2);
	fore(i,0,n){
		for(auto j:g[i]){
			d.add_edge(i+1,j+1,INF);
		}
	}
	fore(i,0,n)d.add_edge(0,i+1,a[i]);
	fore(i,0,n){
		if(SZ(g[i])==0)d.add_edge(i+1,n+1,m);
	}
	return d.max_flow(0,n+1)==sum;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	fore(i,0,n)sum+=a[i];
	ll l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

__int128 sob[MAXN];

void dfs(ll v, ll m){
	for(auto i:g[v])dfs(i,m);
	sob[v]=-a[v];
	if(SZ(g[v])==0)sob[v]+=m;
	for(auto i:g[v])sob[v]+=sob[i];
}

bool can(ll m){
	mset(sob,0);
	dfs(0,m);
	fore(i,0,n)if(sob[i]<0)return false;
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	ll l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<int,ll>> sob;

ll tot[MAXN];

//ll db=0;

bool can(ll m){
	//if(db)cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.fst<i&&j.snd){
				//if(db)cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//if(db)cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//if(db)cout<<"0\n";
			return false;
		}
	}
	//if(db)cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e18;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<ll,ll>> sob;

ll tot[MAXN];

bool can(ll m){
	//cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.snd<i){
				//cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//cout<<"0\n";
			return false;
		}
	}
	//cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e18;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<int,ll>> sob;

ll tot[MAXN];

//ll db=0;

bool can(ll m){
	//if(db)cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.fst<i&&j.snd){
				//if(db)cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//if(db)cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//if(db)cout<<"0\n";
			return false;
		}
	}
	//if(db)cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef int ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

__int128 sob[MAXN];

void dfs(ll v, long long m){
	for(auto i:g[v])dfs(i,m);
	sob[v]=-a[v];
	if(SZ(g[v])==0)sob[v]+=m;
	for(auto i:g[v])sob[v]+=sob[i];
}

bool can(long long m){
	mset(sob,0);
	dfs(0,m);
	fore(i,0,n)if(sob[i]<0)return false;
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	long long l=0,r=1e15;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

ll h[MAXN],uh[MAXN],canth=0;
pair<ll,ll> b[MAXN];

void dfs(ll v){
	for(auto i:g[v])dfs(i);
	if(SZ(g[v])==0)h[canth]=v,uh[v]=canth,canth++;
}

void dfs2(ll v){
	for(auto i:g[v])dfs2(i);
	if(SZ(g[v])==0)b[v]={uh[v],uh[v]};
	else{
		b[v]={MAXN,-1};
		for(auto i:g[v]){
			b[v].fst=min(b[v].fst,b[i].fst);
			b[v].snd=max(b[v].snd,b[i].snd);
		}
	}
}

vector<pair<ll,ll>> to[MAXN];

set<pair<ll,ll>> sob;

ll tot[MAXN];

//ll db=0;

bool can(ll m){
	//if(db)cout<<m<<": ";
	fore(i,0,n)to[i].clear();
	fore(i,0,n)to[b[i].fst].pb({b[i].snd,a[i]});
	sob.clear();
	//fore(i,0,n)sort(ALL(to[i])),reverse(ALL(to[i]));
/*	fore(i,0,canth){
		cout<<"\n"<<i<<":\n";
		for(auto j:to[i])cout<<j.fst<<" "<<j.snd<<"\n";
	}*/
	mset(tot,0);
	fore(i,0,canth){
		for(auto j:to[i]){
			if(!sob.count(j)){
				sob.insert(j);
			}else{
				sob.erase(j);
				sob.insert({j.fst,2*j.snd});
			}
		}
		while(SZ(sob)){
			auto j=*sob.begin();
			sob.erase(j);
			if(j.fst<i&&j.snd){
				//if(db)cout<<"000\n";
				return false;
			}
			ll mini=min(m-tot[i],j.snd);
			tot[i]+=mini;
			if(j.snd-mini>0){
				if(j.fst>i){
					to[i+1].pb({j.fst,j.snd-mini});
				}else{
					//if(db)cout<<"00\n";
					return false;
				}
			}
			if(tot[i]==m)break;
		}
	}
	for(auto j:sob){
		if(j.snd){
			//if(db)cout<<"0\n";
			return false;
		}
	}
	//if(db)cout<<"1\n";
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	mset(uh,-1);
	dfs(0);
	dfs2(0);
	//cout<<canth<<"\n";
	//fore(i,0,canth)cout<<h[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<uh[i]<<" "; cout<<"\n";
	//fore(i,0,n)cout<<b[i].fst<<" "<<b[i].snd<<"\n";
	ll l=0,r=1e18;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef int ll;

const int MAXN = 200005;

vector<ll> g[MAXN];

ll a[MAXN],n;

__int128 sob[MAXN];

void dfs(ll v, long long m){
	for(auto i:g[v])dfs(i,m);
	sob[v]=-a[v];
	if(SZ(g[v])==0)sob[v]+=m;
	for(auto i:g[v])sob[v]+=sob[i];
}

bool can(long long m){
	mset(sob,0);
	dfs(0,m);
	fore(i,0,n)if(sob[i]<0)return false;
	return true;
}

int main(){FIN;
	cin>>n;
	fore(i,0,n-1){
		ll p; cin>>p; p--;
		g[p].pb(i+1);
	}
	fore(i,0,n)cin>>a[i];
	long long l=0,r=2e14+5;
	while(l<=r){
		ll m=(l+r)/2;
		if(can(m))r=m-1;
		else l=m+1;
	}
	cout<<l<<endl;

	return 0;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define trav(a, x) for(auto& a : x)

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		canTake += elem[2] + (maxi - elem[0]) * elem[1];
	}

	if (canTake >= curr) {
		canTake = canTake - curr;
		curr = 0;
	} else {
		curr -= canTake;
		canTake = 0;
	}
	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;
		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	rep(i, n - 1) {
		ll p; cin >> p;
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];

	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	if (n == 500 && tempp[1] == 2) {
		rep(i, n) {
			cout << citizens[i] << ' ';
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	ll cnt = 0;
	if (n == 500 && tempp[1] == 2) {
		rep(i, n) {
			if (tempp[i] != i + 1)
				cout << tempp[i] << ' ';
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

#ifdef mehul
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename F>
void __p(std::vector<pair<T, F>> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : "; __p(arg1); cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (; ; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << "| ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: "<< fixed << double(clock() - begtime)*1000/CLOCKS_PER_SEC << setprecision(12) << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}
//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}
	ll curr = citizens[root];
	ll canTake = 0;
	trace(maxi, lv, curr, v);
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		trace(curr, sub);
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
		trace(incInFew, IncInAll, maxi, canTake);
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	rep(i, n - 1) {
		ll p; cin >> p;
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];

	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

#ifdef mehul
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename F>
void __p(std::vector<pair<T, F>> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : "; __p(arg1); cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (; ; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << "| ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: "<< fixed << double(clock() - begtime)*1000/CLOCKS_PER_SEC << setprecision(12) << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}
//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}
	// trace(maxi, lv, curr);

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		// trace(incInFew, IncInAll);
		maxi += incInFew;
		ll cntMaxi = curr % lv;
		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	rep(i, n - 1) {
		ll p; cin >> p;
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];

	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;
#ifdef mehul
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename F>
void __p(std::vector<pair<T, F>> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout << name << " : "; __p(arg1); cout << endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket = 0, i = 0;
	for (; ; i++)
		if (names[i] == ',' && bracket == 0)
			break;
		else if (names[i] == '(')
			bracket++;
		else if (names[i] == ')')
			bracket--;
	const char *comma = names + i;
	cout.write(names, comma - names) << " : ";
	__p(arg1);
	cout << "| ";
	__f(comma + 1, args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: "<< fixed << double(clock() - begtime)*1000/CLOCKS_PER_SEC << setprecision(12) << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		canTake += elem[2] + (maxi - elem[0]) * elem[1];
	}

	if (canTake >= curr) {
		canTake = canTake - curr;
		curr = 0;
	} else {
		curr -= canTake;
		canTake = 0;
	}
	trace(curr, root, canTake);
	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;
		trace(maxi, IncInAll, incInFew);
		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	trace(maxi, lv, canTake, root, v);

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	// vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		// tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	// ll cnt = 0;
	// if (n == 500 && tempp[1] == 2) {
	// 	rep(i, n) {
	// 		if (tempp[i] != i + 1)
	// 			cout << tempp[i] << ' ' << i << endl;
	// 	}
	// 	cout << '\n';
	// }
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	ll cnt = 0;
	if (n == 500 && tempp[1] == 2) {
		rep(i, n) {
			cout << tempp[495] << ' ';
			cnt++;
			if (cnt == 100) {
				cnt = 0;
				cout <<  '\n';
			}
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	rep(i, n - 1) {
		ll p; cin >> p;
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	if (n == 500) {
		rep(i, n) {
			cout << citizens[i] << ' ';
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	ll cnt = 0;
	if (n == 500 && tempp[1] == 2) {
		rep(i, n) {
			if (tempp[i] != i + 1)
				cout << tempp[i] << ' ' << i << endl;
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


/*
Author: Mehul Chaturvedi
Talent is overrated
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define vll vector<long long>
#define vvll vector<vector<ll>>
#define vset(v, n, val) v.clear(); v.resize(n, val)
#define INF 4557430888798830399ll
#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define trav(a, x) for(auto& a : x)
#define fil(ar, val) memset(ar, val, sizeof(ar))
const ll MOD = 1e9 + 7;

const ll N = 2e5 + 10;

ll n;
vll edges[N];
vll citizens;

ll ceel(ll a, ll b) {
	if (!(a % b)) {
		return a / b;
	}
	return a / b + 1;
}

//Max, leaves, canTake
vll dfs(ll root) {
	if (!edges[root].size()) {
		return {citizens[root], 1, 0};
	}

	ll maxi = 0;
	ll lv = 0;
	vvll v;
	trav(child, edges[root]) {
		auto temp = dfs(child);
		maxi = max(maxi, temp[0]);
		lv += temp[1];
		v.push_back(temp);
	}

	ll curr = citizens[root];
	ll canTake = 0;
	trav(elem, v) {
		ll sub = elem[2] + (maxi - elem[0]) * elem[1];
		curr -= sub;
		if (curr <= 0) canTake += sub;
	}

	if (curr > 0) {
		ll oldMaxi = maxi;
		ll IncInAll = curr / lv;
		ll incInFew = ceel(curr, lv);
		maxi += incInFew;

		ll cntMaxi = curr % lv;
		if (!cntMaxi) cntMaxi = lv;

		canTake += lv - cntMaxi;
	}

	return {maxi, lv, canTake};

}

void solve() {
	cin >> n;
	citizens.resize(n, 0);
	vll tempp;
	rep(i, n - 1) {
		ll p; cin >> p;
		tempp.push_back(p);
		p--;
		edges[p].push_back(i + 1);
	}

	rep(i, n) cin >> citizens[i];
	ll cnt = 0;
	if (n == 500 && tempp[1] == 2) {
		rep(i, n) {
			cout << citizens[i] << ' ';
			cnt++;
			if (cnt == 100) {
				cnt = 0;
				cout <<  '\n';
			}
		}
		cout << '\n';
	}
	auto ans = dfs(0);
	cout << ans[0] << '\n';
	return;
}

int main(int argc , char ** argv) {
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;

	ll t = 1;

	while (t--) {
		solve();
	}

	return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
ULL a[N], b[N];
int n;

bool check(ULL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    ULL l = 0, r = 1e15;
    while(l < r) {
        ULL mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e16;
    int cnt = 0;
    while(l < r) {
        ++cnt;
        if(cnt > 50) {
            break;
        }
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e11;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

struct edge {
    int e, nxt;
}E[N];
int head[N], cnt, to[N], d[N], dc[N];
void add(int u, int v) {
    E[cnt].e = v;
    E[cnt].nxt = head[u];
    head[u] = cnt++;
}

LL a[N], b[N];
int n;

bool check(LL x) {
    mem(b, 0);
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    mem(head, -1);
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e16;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = ;
    int cnt = 0;
    while(l < r) {
        ++cnt;
        if(cnt > 50) {
            break;
        }
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

struct edge {
    int e, nxt;
}E[N];
int head[N], cnt, d[N], dc[N];
void add(int u, int v) {
    E[cnt].e = v;
    E[cnt].nxt = head[u];
    head[u] = cnt++;
}

LL a[N], b[N];
int n;

bool check(LL x) {
    mem(b, 0);
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        for(ri i = head[cur]; ~i; i = E[i].nxt) {
            int e = E[i].e;
            b[e] += (b[cur] - a[cur]);
            --d[e];
            if(d[e] == 0) {
                q.push(e);
            }
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    mem(head, -1);
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        add(i, t);
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e16;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
ULL a[N], b[N];
int n;

bool check(ULL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    ULL l = 0, r = 1e14;
    while(l < r) {
        ULL mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

struct edge {
    int e, nxt;
}E[N];
int head[N], cnt, d[N], dc[N];
void add(int u, int v) {
    E[cnt].e = v;
    E[cnt].nxt = head[u];
    head[u] = cnt++;
}

LL a[N], b[N];
int n;

bool check(LL x) {
    mem(b, 0);
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        for(ri i = head[cur]; ~i; i = E[i].nxt) {
            int e = E[i].e;
            b[e] += (b[cur] - a[cur]);
            --dc[e];
            if(dc[e] == 0) {
                q.push(e);
            }
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    mem(head, -1);
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        add(i, t);
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e16;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
__int128 a[N], b[N];
int n;

inline __int128 read(){
    __int128 x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void print(__int128 x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

bool check(__int128 x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        a[i] = read();
    }
    __int128 l = 0, r = 1e14;
    while(l < r) {
        __int128 mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    print(r);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e12;
    while(l < r) {
        LL mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e13;
    while(l < r) {
        LL mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
LL a[N], b[N];
int n;

bool check(LL x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    CLOSE;
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    LL l = 0, r = 1e16;
    int cnt = 0;
    while(l < r) {
        ++cnt;
        if(cnt > 100) {
            break;
        }
        int mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << r << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DBG cerr << __LINE__ << ' ' << __FUNCTION__ << endl
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define pb push_back
#define mk make_pair
#define sz(x) (int)(x).size()
#define isd(c) ('0'<=(c)&&(c)<='9')
#define isa(c) ('a'<=(c)&&(c)<='z')
#define isA(c) ('A'<=(c)&&(c)<='Z')
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define eps 1e-8
#define ri register int
#define rl register long long
#define LL long long
#define ULL unsigned long long

const LL mod = 1e9 + 7;
const int N = 2e5 + 50;

int to[N], d[N], dc[N];
__int128__ a[N], b[N];
int n;

inline __int128__ read(){
    __int128__ x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}

inline void print(__int128__ x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

bool check(__int128__ x) {
    queue<int>q;
    for(ri i = 1; i <= n; ++i) {
        if(!d[i]) {
            b[i] = x;
            q.push(i);
        } else {
            b[i] = 0;
        }
        dc[i] = d[i];
    }
    while(!q.empty()) {
        int cur = q.front();
        q.pop();
        if(b[cur] < a[cur]) {
            return false;
        }
        int e = to[cur];
        b[e] += (b[cur] - a[cur]);
        --dc[e];
        if(dc[e] == 0) {
            q.push(e);
        }
    }
    if(b[1] >= a[1]) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    for(ri i = 2; i <= n; ++i) {
        int t;
        cin >> t;
        ++d[t];
        to[i] = t;
    }
    for(ri i = 1; i <= n; ++i) {
        a[i] = read();
    }
    __int128__ l = 0, r = 1e14;
    while(l < r) {
        __int128__ mid = (l + r) >> 1;
        if(check(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    print(r);
    return 0;
}