//#pragma GCC optimize("unroll-loops, O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
int n, a[1000000], cnt[1000000], mx[1000000];
vector<int> adj[1000000];
void dfs(int vtx, int pre){
mx[vtx] = 0, cnt[vtx] = a[vtx];
for(int i : adj[vtx])
if(i != pre){
dfs(i, vtx);
cnt[vtx] += cnt[i];
mx[vtx] = max(mx[vtx], cnt[i]);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0, -1);
pair<int, int> ans(INT_MAX, -1);
for(int i = 0; i < n; i++)
ans = min(ans, make_pair(max(cnt[0] - cnt[i], mx[i]), i));
cout << ans.second << '\n';
return 0;
}
Compilation message
/tmp/cce6FV2X.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccIEDHaU.o:traffic.cpp:(.text.startup+0x0): first defined here
/tmp/cce6FV2X.o: In function `main':
grader.cpp:(.text.startup+0xd9): undefined reference to `LocateCentre(int, int*, int*, int*)'
collect2: error: ld returned 1 exit status