# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377769 | meperdonas203 | Traffic (IOI10_traffic) | C++17 | 16 ms | 23788 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>
#include <vector>
using namespace std;
vector <int> adjacencia[1000002];
int sub_arb[1000002];
int menor=INT_MAX;
int ans=0;
int dfs(int nodo,int anterior){
for(int i=0;i<adjacencia[nodo].size();i++){
if(adjacencia[nodo][i]!=anterior){
sub_arb[nodo]+=dfs(adjacencia[nodo][i],nodo);
}
}
return sub_arb[nodo];
}
void respuesta(int nodo,int anterior){
int maximo=0;
int hijo=0;
for(int i=0;i<adjacencia[nodo].size();i++){
if(sub_arb[adjacencia[nodo][i]]>maximo){
hijo=i;
maximo=sub_arb[adjacencia[nodo][i]];
}
}
if(maximo<menor){
ans=hijo;
menor=maximo;
}
if(hijo==anterior){
return ;
}
sub_arb[nodo]-=sub_arb[hijo];
sub_arb[hijo]+=sub_arb[nodo];
respuesta(hijo,anterior);
return;
}
int LocateCentre(int N, int pp[], int S[], int D[]) {
for(int i=0;i<N;i++){
sub_arb[i]=pp[i];
}
for(int i= 0;i<=N-2;i++){
adjacencia[S[i]].push_back(D[i]);
adjacencia[D[i]].push_back(S[i]);
}
dfs(0,0);
respuesta(0,0);
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |