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;
vector<int> adj[1000100];
int n, opt, a[1000100];
long long res = 1e18, sum = 0;
long long cal(int x, int pa) {
long long mv = 0, s = 0;
for (int i = 0; i < (int) adj[x].size(); i++) {
if (adj[x][i] == pa) continue;
long long t = cal(adj[x][i], x);
s += t;
mv = max(mv, t);
}
s += a[x];
mv = max(mv, sum - s);
if (res > mv) {
res = mv; opt = x;
}
return s;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
n = N;
for (int i = 0; i < n; i++) {
a[i] = pp[i];
sum += a[i];
}
for (int i = 0; i < n - 1; i++) {
adj[S[i]].push_back(D[i]);
adj[D[i]].push_back(S[i]);
}
cal(0, -1);
return opt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |