Submission #339149

#TimeUsernameProblemLanguageResultExecution timeMemory
339149Ta180mTraffic (IOI10_traffic)C++17
0 / 100
14 ms23788 KiB
#include "traffic.h" #include <bits/stdc++.h> #define f first #define s second using namespace std; using ll = long long; using ii = pair<int, int>; constexpr int MX = 1e6+5; int sum, sz[MX]; ii ans; vector<int> G[MX]; void dfs(int u, int p) { for (int v : G[u]) if (v != p) dfs(v, u), sz[u] += sz[v]; } void solve(int u, int p, int P[]) { int up = sum-P[u], mx = 0; for (int v : G[u]) if (v != p) up -= sz[v], mx = max(sz[v], mx); mx = max(up, mx); if (mx < ans.f) ans = ii(mx, u); for (int v : G[u]) if (v != p) dfs(v, u); } int LocateCentre(int N, int P[], int S[], int D[]) { for (int i = 0; i < N-1; ++i) G[S[i]].push_back(D[i]), G[D[i]].push_back(S[i]); for (int i = 0; i < N; ++i) sum += P[i], sz[i] = P[i]; dfs(0, -1); solve(0, -1, P); return ans.s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...