제출 #928598

#제출 시각아이디문제언어결과실행 시간메모리
928598OAleksaTraffic (IOI10_traffic)C++14
100 / 100
927 ms170660 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; for (auto u : g[v]) { if (u == p) continue; mx = max(mx, dp[u]); } mx = max(mx, dp[0] - dp[v]); 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(0, -1); solve(0, -1); 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...