# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
676212 | lebasivillar | Traffic (IOI10_traffic) | C++14 | 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;
const int MAXN = 1e6 + 5;
int n;
int p[MAXN];
int s[MAXN], d[MAXN];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> s[i] >> d[i];
}
int minCongestion = INT_MAX;
int minCongestionCity;
for (int i = 0; i < n; i++) {
int congestion = 0;
for (int j = 0; j < n - 1; j++) {
if (s[j] == i || d[j] == i) {
congestion += p[s[j]] + p[d[j]];
}
}
if (congestion < minCongestion) {
minCongestion = congestion;
minCongestionCity = i;
}
}
cout << minCongestionCity << endl;
return 0;
}