제출 #881402

#제출 시각아이디문제언어결과실행 시간메모리
88140212345678Traffic (IOI10_traffic)C++17
50 / 100
348 ms145364 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; const int nx=1e6+5; vector<int> d[nx], dp(nx), dpr(nx), sm(nx), c(nx); void dfs(int u, int p) { sm[u]=c[u]; for (auto v:d[u]) if (v!=p) dfs(v, u), sm[u]+=sm[v], dp[u]=max(dp[u], sm[v]); } void dfs2(int u, int p) { int tmp=0; for (auto v:d[u]) if (v!=p) tmp+=dp[v]; for (auto v:d[u]) if (v!=p) dpr[v]=tmp-dp[v]+dpr[u]+c[u], dfs2(v, u); } int LocateCentre(int N, int pp[], int S[], int D[]) { for (int i=0; i<N-1; i++) d[S[i]].push_back(D[i]), d[D[i]].push_back(S[i]); for (int i=0; i<N; i++) c[i]=pp[i]; dfs(0, 0); dfs2(0, 0); pair<int, int> res={INT_MAX, -1}; for (int i=0; i<N; i++) res=min(res, {max(dp[i], dpr[i]), i}); //for (int i=0; i<N; i++) cout<<i<<' '<<dp[i]<<' '<<dpr[i]<<'\n'; return res.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...