#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18,MOD=1e9+7,LOG=17;
const int SQ=317;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) {cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }

void Md(ll& x){
    if(x>=MOD) x%=MOD;
}



void Solve(){
    int N; cin>>N;
    vector<int> adj[N+1];
    for(int i=1;i<=N-1;i++){
        int u,v; cin>>u>>v;
        adj[u].pb(v); adj[v].pb(u);
    }
    ll suma=0;
    vector<ll> a(N+1,0);
    for(int i=1;i<=N;i++){
        cin>>a[i];
        suma+=a[i];
    }

    vector<ll> podstablo_suma(N+1,0),nadstablo_suma(N+1,0),podstablo(N+1,0);
    function<void(int,int)> Dfs1=[&](int node,int prev){
        podstablo_suma[node]=a[node];
        for(auto v:adj[node]){
            if(v!=prev){
                Dfs1(v,node);
                podstablo_suma[node]+=podstablo_suma[v];
                podstablo[node]+=podstablo[v]+podstablo_suma[v];
            }
        }
        nadstablo_suma[node]=suma-podstablo_suma[node]+a[node];
        //PRINT(node);
        //PRINT(podstablo_suma[node]);
        //PRINT(podstablo[node]);
        //PRINT(nadstablo_suma[node]);
        cerr<<endl;
    }; Dfs1(1,1);
    vector<ll> nadstablo(N+1,0);
    pll res={INF,INF};
    ll x=0;
    function<void(int,int,int)> Dfs2=[&](int node,int prev,ll x=0){
        if(prev!=-1){
            nadstablo[node]+=nadstablo[prev]+nadstablo_suma[prev]+x-(podstablo[node]+podstablo_suma[node]);
        }
        for(auto v:adj[node]){
            if(v!=prev) x+=podstablo[v]+podstablo_suma[v];
        }
        for(auto v:adj[node]){
            if(v!=prev) Dfs2(v,node,x);
        }
        res=min(res,{nadstablo[node]+podstablo[node],node});
    }; Dfs2(1,-11,x);
    int Q; cin>>Q; if(Q!=0) exit(13);
    cout<<res.se<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1;
    //cin>>t;;
    while(t--){
        Solve();
    }
    return 0;
}