Submission #528275

#TimeUsernameProblemLanguageResultExecution timeMemory
528275meperdonas203Traffic (IOI10_traffic)C++17
0 / 100
12 ms23756 KiB
#include "traffic.h" #include<bits/stdc++.h> using namespace std; int sub[1000005]; vector<int>grafo[1000005]; int padres[1000005]; int dfs(int nodo,int padre,int arre[]){ sub[nodo]+=arre[nodo]; padres[nodo]=padre; for(auto x:grafo[nodo]){ if(x!=padre){ sub[nodo]+=dfs(x,nodo,arre); } } return sub[nodo]; } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...