# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370898 | XEMPLI5 | Traffic (IOI10_traffic) | C++17 | 0 ms | 0 KiB |
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){
subTreeSize[cur] = citySize[cur];
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]);
}
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];
citiySize[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;
}