# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
373308 | No_Ice | Traffic (IOI10_traffic) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN = 1e6;
const ll INF = 1e17;
int N;
vector<int> adj[mxN];
ll fans[mxN];
ll ans = INF;
ll dfs(int u, int p = -1) {
ll sum = 0;
for (int v : adj[u]) {
if (v != p) {
ll c_sum = 0;
c_sum += fans[v];
c_sum += dfs(v, u);
sum = max(sum, c_sum);
}
}
return sum;
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin >> N;
for (int i=0; i < N; i++) {
cin >> fans[i];
}
for (int i=0; i < N-1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int ans1 = 0;
for (int i=0; i < N; i++) {
ll temp = dfs(i);
if (temp < ans) {
ans = temp;
ans1 = i;
}
}
cout << ans1 << '\n';
return 0;
}