# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528252 | AlexRex0 | 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 "grader.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000002];
long long int congestion[1000002];
long long int ans = -1, posAns = -1;
long long int dfs(int nodo, int padre, int pp[]){
long long int suma = pp[nodo];
for(int i = 0; i < g[nodo].size(); ++i){
int sig = g[nodo][i];
if(sig != padre){
suma+= dfs(sig, nodo, pp);
}
}
congestion[nodo] = suma;
return suma;
}
void dfs2(int nodo, int padre){
if(nodo != 0){
long long int M = max(congestion[0] - congestion[nodo], congestion[nodo]);
if(M < ans){
ans = M;
posAns = nodo;
}
}
for(int i = 0; i < g[nodo].size(); ++i){
int sig = g[nodo][i];
if(sig != padre){
dfs2(sig, nodo);
}
}
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
for(int i = 0; i < N - 1; ++i){
g[S[i]].push_back(D[i]);
g[D[i]].push_back(S[i]);
}
dfs(0, -1, pp);
posAns = 0;
ans = congestion[0];
dfs2(0, -1);
return posAns;
}