#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200010;
vector<long long> graf[MAXN];
long long niz[MAXN];
long long dist[MAXN];
bool visited[MAXN];
int main(){
	long long n, q;
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		long long a, b;
		scanf("%lld %lld", &a, &b);
		graf[a].push_back(b);
		graf[b].push_back(a);
	}
	for(int i = 1; i <= n; i++)
		scanf("%lld",&niz[i]);
	long long res = 0, mindist = 1e17;
	for(int i = 1; i <= n; i++){
		long long sum = 0;
		memset(visited, false, sizeof(visited));
		memset(dist, 0, sizeof(dist));
		queue<long long> q;
		dist[i] = 0;
		q.push(i);
		visited[i] = true;
		long long trmaxdist = -1;
		while(!q.empty()){
			auto vrh = q.front();
			q.pop();
			for(auto y : graf[vrh]){
				if(!visited[y]){
					visited[y] = true;
					dist[y] = dist[vrh] + 1;
					q.push(y);
				}
			}
		}
		for(int j = 1; j <= n; j++){
			//cout << "rastojanje od " << i << " do " << j << " je " << dist[j] << endl; 
			sum += (niz[j] * dist[j]);
		}
		/*cout << sum << endl;*/
		if(sum < mindist){
			mindist = sum;
			res = i;
		}
	}
	cout << res;
	return 0;
}