# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
403157 | Nafeeszx | Traffic (IOI10_traffic) | C++14 | 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;
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]);
}
int minpeople = 2e9 + 1, res = 0;
for(int i = 0; i < n; ++i){
if(people[i] < minpeople){
res = i;
minpeople = people[i];
}
}
return res;
}