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 fans, mxN = 1e6;
vector<vector<int>> g(mxN);
vector<int> citySize(mxN), subTreeSize(mxN), maxTraffic(mxN), people(mxN);
void dfs(int cur, int par){
for(auto e: g[cur]) {
if(e == par) return;
dfs(e,par);
subTreeSize[cur] += subTreeSize[e];
people[cur] = max(people[cur], subTreeSize[e]);
}
people[cur] = max(people[cur], fans - subTreeSize[cur] - citySize[cur]);
subTreeSize[cur] += citySize[cur];
}
int LocateCentre(int n, int p[], int s[], int d[]){
for(int i=0; i<n; i++){
g[s[i]].push_back(d[i]);
g[d[i]].push_back(s[i]);
}
for(int i=0; i<n; i++) {
fans += p[i];
citySize[i] = p[i];
}
dfs(0,0);
int ans = 0, minPeople = 1e9;
for(int i=0; i<n; i++){
if(people[i] < minPeople) {
minPeople = people[i];
ans = i;
}
}
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... |