제출 #485568

#제출 시각아이디문제언어결과실행 시간메모리
485568M_WTraffic (IOI10_traffic)C++14
100 / 100
1044 ms166856 KiB
#include <bits/stdc++.h> #define ii pair<int, int> using namespace std; vector<int> adj[1000001]; int dp[1000001]; ii ans = make_pair(INT_MAX, -1); int dfs(int a, int p){ for(auto x : adj[a]){ if(x == p) continue; dp[a] += dfs(x, a); } return dp[a]; } void dfs2(int a, int p, int s){ int tmp = s; for(auto x : adj[a]){ if(x == p) continue; tmp = max(tmp, dp[x]); dfs2(x, a, s + dp[a] - dp[x]); } if(tmp < ans.first) ans = make_pair(tmp, a); return; } int LocateCentre(int N, int P[], int S[], int D[]){ for(int i = 0; i < N - 1; i++){ adj[S[i]].push_back(D[i]); adj[D[i]].push_back(S[i]); dp[i] = P[i]; } dp[N - 1] = P[N - 1]; dfs(0, -1); dfs2(0, -1, 0); return ans.second; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...