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<vector<int>> g;
vector<int> sz, a;
int ans = INT_MAX;
void dfs(int u, int p) {
sz[u] = a[u];
for (int v : g[u])
if (v ^ p)
dfs(v, u), sz[u] += sz[v];
}
void solve(int u, int p) {
int x = sz[0] - sz[u];
for (int v : g[u])
if (v ^ p)
solve(v, u), x = max(x, sz[v]);
ans = min(ans, x);
}
int LocateCentre(int n, int p[], int s[], int d[]) {
g.resize(n);
for (int i = 0; i < n; i++) a[i] = p[i];
for (int i = 0; i < n - 1; i++) {
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
dfs(0, 0);
solve(0, 0);
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... |