제출 #390154

#제출 시각아이디문제언어결과실행 시간메모리
390154Alex_tz307Traffic (IOI10_traffic)C++17
50 / 100
584 ms180256 KiB
#include <bits/stdc++.h> using namespace std; using int64 = long long; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } const int NMAX = 1e6 + 6; int a[NMAX], ans; int64 dp[NMAX], sum[NMAX]; vector<int> G[NMAX]; void dfs1(int u, int parent) { sum[u] = a[u]; for (int v : G[u]) if (v != parent) { dfs1(v, u); sum[u] += sum[v]; if (sum[v] > dp[u]) dp[u] = sum[v]; } } void dfs2(int u, int parent, int64 s) { if (dp[u] < dp[ans]) ans = u; for (int v : G[u]) if (v != parent) { int64 aux = dp[v]; if (s + a[u] > dp[v]) dp[v] = s + a[u]; dfs2(v, u, s + a[u]); dp[v] = aux; } } int LocateCentre(int N, int pp[], int S[], int D[]) { for (int i = 0; i < N - 1; ++i) { G[S[i]].emplace_back(D[i]); G[D[i]].emplace_back(S[i]); } for (int i = 0; i < N; ++i) a[i] = pp[i]; dfs1(0, -1); dfs2(0, -1, 0); 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...