Submission #614664

#TimeUsernameProblemLanguageResultExecution timeMemory
614664kbk0421Traffic (IOI10_traffic)C++17
100 / 100
918 ms167700 KiB
#include <iostream> #include <vector> #include <numeric> #define INF 1e9 using namespace std; vector<int> G[1000010]; int d[1000010]; bool visited[1000010]; int sum; int mn = INF; int ans; int dfs(int x, int *P) { visited[x] = 1; int &ret = d[x] = P[x]; int mx = 0; for(auto &p : G[x]){ if(visited[p]) continue; int s = dfs(p,P); ret += s; mx = max(s, mx); } mx = max(sum-ret, mx); if(mx<mn){ mn = mx; ans = x; } return ret; } int LocateCentre(int N, int P[], int S[], int D[]) { for(int i=0; i<N-1; i++){ G[S[i]].push_back(D[i]); G[D[i]].push_back(S[i]); } sum = accumulate(P,P+N,0); dfs(0,P); 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...