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 trav(a, x) for(auto& a : x)
const int MX = 1e6;
vector<int> adj[MX];
vector<int> nodes(MX);
vector<int> children(MX);
vector<int> people(MX, 0);
int citizen = 0;
void dfs(int u, int p){
trav(v, adj[u]){
if(v != p){
dfs(v, u);
children[u] += children[v];
people[u] = max(people[u], children[v]);
}
}
people[u] = max(people[u], citizen - children[u] - nodes[u]);
children[u] += nodes[u];
}
int LocateCentre(int n, int p[], int s[], int d[]){
for(int i = 0; i < n; ++i){
nodes[i] = p[i];
citizen += 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 minpeople = 2e9 + 1, res = 0;
for(int i = 0; i < n; ++i){
if(people[i] < minpeople){
res = i;
minpeople = people[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... |