# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
528253 | meperdonas203 | 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>
int sub[1000005];
vector<int>grafo[1000005];
int padres[1000005];
int dfs(int nodo,int padre,int arre[]){
sub[i]+=arre[nodo];
padres[nodo]=padre;
for(auto x:grafo[nodo]){
if(x!=padre){
sub[i]+=dfs(x,nodo,arre);
}
}
return sub[i];
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
dfs(0,-1,pp);
for(int i=0;i<N-1;i++){
grafo[S[i]].push_back(D[i]);
grafo[D[i]].push_back(S[i]);
}
int ans=-1;
int ans_res=INT_MAX;
for(int i=0;i<N;i++){
int res=sub[0]-sub[i];
for(int x:grafo[i]){
if(x!=padres[i])res=max(res,sub[x]);
}
if(res<=ans_res){
ans=i;
ans_res=res;
}
}
return ans;
}