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
const int MAXN = 1e6, MAXN2 = 2e9+1;
int total = 0, ans = MAXN2;
vector<int> adj[MAXN], biggest(MAXN, 0), children(MAXN, 0);
void dfs(int vertex, int parent, int p[]) {
for(int next: adj[vertex]) {
if(next != parent) {
dfs(next, vertex, p);
children[vertex] += children[next];
biggest[vertex] = max(children[next], biggest[vertex]);
}
}
biggest[vertex] = max(biggest[vertex], total-p[vertex]-children[vertex]);
children[vertex] += p[vertex];
}
int LocateCentre(int n, int p[], int s[], int d[]) {
for(int i=0; i<(n-1); i++) {
adj[s[i]].push_back(d[i]);
adj[d[i]].push_back(s[i]);
}
for(int i=0; i<n; i++) {
total += p[i];
}
dfs(0, -1, p);
int res = 0;
for(int i=0; i<n; i++) {
if(biggest[i] < ans) {
res = i;
ans = biggest[i];
}
}
return res;
}
# | 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... |