Submission #517026

#TimeUsernameProblemLanguageResultExecution timeMemory
517026AdamGSTraffic (IOI10_traffic)C++17
100 / 100
952 ms186500 KiB
#include "traffic.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=1e6+7; const ll INF=1e18+7; vector<int>V[LIM]; ll T[LIM], dp[LIM], oc[LIM], sum; void DFS(int x, int o) { dp[x]=T[x]; for(auto i : V[x]) if(i!=o) { oc[i]=x; DFS(i, x); dp[x]+=dp[i]; } } int LocateCentre(int n, int pp[], int S[], int D[]) { rep(i, n) { T[i]=pp[i]; sum+=T[i]; } rep(i, n-1) { V[S[i]].pb(D[i]); V[D[i]].pb(S[i]); } DFS(0, 0); pair<ll,ll>ans={INF, INF}; rep(i, n) { ll ma=sum-dp[i]; for(auto j : V[i]) if(j!=oc[i]) ma=max(ma, dp[j]); pair<ll,ll>p={ma, i}; ans=min(ans, p); } return ans.nd; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...