(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #296436

#TimeUsernameProblemLanguageResultExecution timeMemory
296436moratoTraffic (IOI10_traffic)C++17
100 / 100
1253 ms170744 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; vector<int> adj[maxn]; int64_t p[maxn], h[maxn], sub[maxn]; void dfs(int v, int _p = -1) { sub[v] = p[v]; for (int u : adj[v]) if (u != _p) { dfs(u, v); sub[v] += sub[u]; h[v] = max(h[v], sub[u]); } } int LocateCentre(int N, int P[], int S[], int D[]) { int64_t tot = 0; for (int i = 0; i < N; i++) { p[i] = 1ll * P[i]; tot += p[i]; } for (int i = 0; i < N - 1; i++) { adj[S[i]].push_back(D[i]); adj[D[i]].push_back(S[i]); } dfs(0); assert(sub[0] == tot); int ans = 0; int64_t heavy = h[0]; for (int i = 1; i < N; i++) { h[i] = max(h[i], sub[0] - sub[i]); if (h[i] < heavy) { heavy = h[i]; ans = i; } } 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...