제출 #390159

#제출 시각아이디문제언어결과실행 시간메모리
390159Alex_tz307Traffic (IOI10_traffic)C++17
0 / 100
17 ms23824 KiB
#include <bits/stdc++.h> using namespace std; void fastIO() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } const int NMAX = 1e6; int a[NMAX], dp[NMAX], sum[NMAX], ans; vector<int> G[NMAX]; void dfs(int u, int parent) { sum[u] = a[u]; for (int v : G[u]) if (v != parent) { dfs(v, u); sum[u] += sum[v]; if (sum[v] > dp[u]) dp[u] = sum[v]; } } 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 u = 0; u < N; ++u) a[u] = pp[u]; dfs(0, -1); for (int u = 0; u < N; ++u) { if (sum[1] - sum[u] > dp[u]) dp[u] = dp[1] - sum[u]; if (dp[u] < dp[ans]) ans = u; } return ans; } /*int N, P[NMAX], S[NMAX], D[NMAX]; int main() { fastIO(); cin >> N; for (int i = 0; i < N; ++i) cin >> P[i]; for (int i = 0; i < N - 1; ++i) cin >> S[i] >> D[i]; cout << LocateCentre(N, P, S, D) << '\n'; return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...