Submission #928593

#TimeUsernameProblemLanguageResultExecution timeMemory
928593OAleksaTraffic (IOI10_traffic)C++14
0 / 100
6 ms33372 KiB
#include "traffic.h" #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 69; int dp[N], a[N], ans = 2e9 + 69, gas = -1; vector<int> g[N]; void dfs(int v, int p) { dp[v] = a[v]; for (auto u : g[v]) { if (u == p) continue; dfs(u, v); dp[v] += dp[u]; } } void solve(int v, int p) { int mx = 0, s = 0; for (auto u : g[v]) { if (u == p) continue; s += dp[u]; mx = max(mx, dp[u]); } mx = max(mx, dp[1] - s); if (mx <= ans) { gas = v; ans = mx; } for (auto u : g[v]) { if (u == p) continue; solve(u, v); } } int LocateCentre(int n, int p[], int u[], int v[]) { for (int i = 0;i < n;i++) a[i] = p[i]; for (int i = 0;i < n - 1;i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dfs(1, 0); solve(1, 0); return gas; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...