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 "traffic.h"
#include <bits/stdc++.h>
using namespace std;
int LocateCentre(int n, int *a, int *s, int *d) {
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; ++i) {
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
array<int, 2> res = {INT_MAX, -1};
vector<int> sz(n);
int tot = accumulate(a, a + n, 0);
function<void(int)> dfs = [&](int u) {
sz[u] = a[u];
int ma = 0;
for (int v : g[u]) {
if (!sz[v]) {
dfs(v);
ma = max(ma, sz[v]);
sz[u] += sz[v];
}
}
ma = max(ma, tot - sz[u]);
res = min(res, {ma, u});
};
dfs(0);
return res[1];
}
# | 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... |