(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

제출 #241751

#제출 시각아이디문제언어결과실행 시간메모리
241751davi_bartTraffic (IOI10_traffic)C++14
100 / 100
1464 ms138080 KiB
#include <bits/stdc++.h> using namespace std; vector<int> v[1000009]; int k[1000009]; int mi=2e9,best=0; vector<int>p; int dfs(int pos,int prec){ int val=p[pos]; for(int s:v[pos])if(s!=prec)val+=dfs(s,pos); return k[pos]=val; } void root(int pos,int prec){ int ma=0; for(int s:v[pos])ma=max(ma,k[s]); if(ma<mi){ mi=ma; best=pos; } for(int s:v[pos]){ if(s==prec)continue; k[pos]-=k[s]; k[s]+=k[pos]; root(s,pos); k[s]-=k[pos]; k[pos]+=k[s]; } } int LocateCentre(int N,int P[],int S[],int D[]){ for(int i=0;i<N-1;i++){ v[S[i]].push_back(D[i]); v[D[i]].push_back(S[i]); } for(int i=0;i<N;i++)p.push_back(P[i]); dfs(0,-1); root(0,-1); return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...