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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int v[1000005], sum, c[1000005], ch[1000005];
vector<int> adj[1000005];
void dfs(int x, int par) {
for (int i : adj[x]) {
if (i == par) continue;
dfs(i, x);
ch[x] += ch[i];
c[x] = max(c[x], ch[i]);
}
c[x] = max(c[x], sum - ch[x] - v[x]);
ch[x] += v[x];
}
int LocateCentre(int n, int p[], int s[], int d[]) {
for (int i = 0; i < n; i++) {
sum += p[i];
v[i] = p[i];
}
for (int i = 0; i < n - 1; i++) {
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
dfs(0, -1);
int m = 2e9 + 5, ans = -1;
for (int i = 0; i < n; i++) {
if (c[i] < m) {
m = c[i];
ans = i;
}
}
return ans;
}
# | 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... |