# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
503203 | Hacv16 | 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<bits/stdc++.h>
#include "traffic.h"
using namespace std;
const int MAX = 1e6 + 15;
const int INF = 0x3f3f3f3f;
int fans = 0;
vector<int> adj[MAX], child(MAX), cong(MAX), fan(MAX);
void dfs(int x, int p){
for(auto v : adj[x]){
if(v == p) continue;
dfs(v, x);
child[x] += child[v];
cong[x] = max(cong[x], child[v]);
}
cong[x] = max(cong[x], fans - child[x] - fan[x]);
child[x] += fan[x];
}
int LocateCentre(int n, int p[], int s[], int d[]){
for(int i = 0; i < n; i++){
fans += p[i];
fan[i] = p[i];
}
for(int i = 0; i < n - 1; i++){
adj[s[i]].pb(d[i]);
adj[d[i]].pb(s[i]);
}
dfs(0, -1);
int id = -1, sm = INF;
for(int i = 0; i < n; i++){
if(cong[i] < sm){
id = i, sm = cong[i];
}
}
return id;
}