Submission #591622

#TimeUsernameProblemLanguageResultExecution timeMemory
591622ogibogi2004Traffic (IOI10_traffic)C++14
100 / 100
1061 ms170836 KiB
#include "traffic.h" #include<bits/stdc++.h> using namespace std; const int INF=2e9+1; const int MAXN=1e6+6; vector<int>g[MAXN]; int sz[MAXN]; int cnt[MAXN]; int all_people=0; int min_cong=INF; int arena=-1; void dfs(int u,int par) { sz[u]=cnt[u]; int max_cong=0; for(auto xd:g[u]) { if(xd==par)continue; dfs(xd,u); max_cong=max(max_cong,sz[xd]); sz[u]+=sz[xd]; } max_cong=max(max_cong,all_people-sz[u]); if(max_cong<min_cong) { min_cong=max_cong; arena=u; } } int LocateCentre(int N, int pp[], int S[], int D[]) { for(int i=0;i<N;i++) { cnt[i]=pp[i]; all_people+=pp[i]; } 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); return arena; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...