#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <tr1/unordered_map>
using namespace std;
using namespace tr1;
typedef pair<int, int> pi;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
vector< int > v;
vector< int > adj[N];
unordered_map<int, unordered_map<int, ld> > dp;
unordered_map<int, unordered_map<int, ld> > done;
ld memo[N];
ld solve(int cur, int par){
if(dp.count(cur) && dp[cur].count(par)){
return dp[cur][par];
}
ld &ret = dp[cur][par];
ret = v[cur];
ld tot = 0;
if(done.count(cur) && done[cur].size() == adj[cur].size()){
if(par != 0){
tot = memo[cur] - done[cur][par];
}else{
tot = memo[cur];
}
}else{
for(int i = 0; i < adj[cur].size(); i++){
int to = adj[cur][i];
if(to == par) continue;
ld val = solve(to, cur);
if(done[cur].count(to) == 0){
done[cur][to] = val;
memo[cur] += val;
}
tot += val;
}
}
if(adj[cur].size() - (par != 0) != 0) tot /= adj[cur].size() - (par != 0);
ret += tot;
return ret;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
//freopen("out.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n, x, a, b;
cin >> n;
v.push_back(0);
for(int i = 0; i < n; i++){
cin >> x;
v.push_back(x);
}
for(int i = 1; i < n; i++){
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
ld best = 1e200;
int ans = -1;
for(int i = 1; i <= n; i++){
ld cur = solve(i, 0);
if(cur < best){
best = cur;
ans = i;
}
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGxpc3Q+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxxdWV1ZT4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gICBpZihkb25lLmNvdW50KGN1cikgJiYgZG9uZVtjdXJdLnNpemUoKSA9PSBhZGpbY3VyXS5zaXplKCkpewogICAgICAgIGlmKHBhciAhPSAwKXsKICAgICAgICAgICAgdG90ID0gbWVtb1tjdXJdIC0gZG9uZVtjdXJdW3Bhcl07CiAgICAgICAgfWVsc2V7CiAgICAgICAgICAgIHRvdCA9IG1lbW9bY3VyXTsKICAgICAgICB9CiAgICB9ZWxzZXsKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgYWRqW2N1cl0uc2l6ZSgpOyBpKyspewogICAgICAgICAgICBpbnQgdG8gPSBhZGpbY3VyXVtpXTsKICAgICAgICAgICAgaWYodG8gPT0gcGFyKSBjb250aW51ZTsKICAgICAgICAgICAgbGQgdmFsID0gc29sdmUodG8sIGN1cik7CiAgICAgICAgICAgIGlmKGRvbmVbY3VyXS5jb3VudCh0bykgPT0gMCl7CiAgICAgICAgICAgICAgICBkb25lW2N1cl1bdG9dID0gdmFsOwogICAgICAgICAgICAgICAgbWVtb1tjdXJdICs9IHZhbDsKICAgICAgICAgICAgfQogICAgICAgICAgICB0b3QgKz0gdmFsOwogICAgICAgIH0KICAgIH0KICAgIGlmKGFkaltjdXJdLnNpemUoKSAtIChwYXIgIT0gMCkgIT0gMCkgdG90IC89IGFkaltjdXJdLnNpemUoKSAtIChwYXIgIT0gMCk7CiAgICByZXQgKz0gdG90OwogICAgcmV0dXJuIHJldDsKfQoKaW50IG1haW4oKXsKI2lmbmRlZiBPTkxJTkVfSlVER0UKICAgIGZyZW9wZW4oImluLmluIiwgInIiLCBzdGRpbik7CiAgICAvL2ZyZW9wZW4oIm91dC5vdXQiLCAidyIsIHN0ZG91dCk7CiNlbmRpZgogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZSgwKTsKCiAgICBpbnQgbiwgeCwgYSwgYjsKICAgIGNpbiA+PiBuOwogICAgdi5wdXNoX2JhY2soMCk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKXsKICAgICAgICBjaW4gPj4geDsKICAgICAgICB2LnB1c2hfYmFjayh4KTsKICAgIH0KICAgIGZvcihpbnQgaSA9IDE7IGkgPCBuOyBpKyspewogICAgICAgIGNpbiA+PiBhID4+IGI7CiAgICAgICAgYWRqW2FdLnB1c2hfYmFjayhiKTsKICAgICAgICBhZGpbYl0ucHVzaF9iYWNrKGEpOwogICAgfQoKICAgIGxkIGJlc3QgPSAxZTIwMDsKICAgIGludCBhbnMgPSAtMTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKICAgICAgICBsZCBjdXIgPSBzb2x2ZShpLCAwKTsKICAgICAgICBpZihjdXIgPCBiZXN0KXsKICAgICAgICAgICAgYmVzdCA9IGN1cjsKICAgICAgICAgICAgYW5zID0gaTsKICAgICAgICB9CiAgICB9CgogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKCiAgICByZXR1cm4gMDsKfQo=