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;
#define ll long long
#define fi first
#define se second
#define sz(a) (long long) a.size()
#define endl '\n'
const long long INF = 1e18, MOD = 1e9+7;
int LocateCentre(int n, int* P, int* S, int *D) {
int tot = 0;
for (int i = 0; i < n; i++) {
tot += P[i];
}
vector g(n, vector<int>());
for (int i = 0; i < n - 1; i++) {
g[S[i]].push_back(D[i]);
g[D[i]].push_back(S[i]);
}
int mn = 2e9+5, who = -1;
function<int(int, int)> Dfs = [&](int v, int par) {
int down = 0, mx = 0;
for (auto u : g[v]) {
if (u == par) continue;
int x = Dfs(u, v);
mx = max(mx, x);
down += x;
}
down += P[v];
mx = max(mx, tot - down);
if (mx < mn) {
mn = mx;
who = v;
}
return down;
};
Dfs(0, -1);
return who;
}
//signed main() {
//ios_base::sync_with_stdio(false);
//cin.tie(0);
//int tt = 1;
//cin >> tt;
//while (tt--) {
//test_case();
//}
//return 0;
//}
# | 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... |