Submission #854965

#TimeUsernameProblemLanguageResultExecution timeMemory
854965thinknoexitTraffic (IOI10_traffic)C++17
100 / 100
945 ms182992 KiB
#include <bits/stdc++.h> #include "traffic.h" using namespace std; using ll = long long; const ll INF = 1e18; const int N = 1001000; ll dp[2][N]; vector<int> adj[N]; int a[N], ans = -1; ll mn = INF; void dfs(int v, int p = -1) { dp[0][v] = dp[1][v] = 0; for (auto& x : adj[v]) { if (x == p) continue; dfs(x, v); dp[0][v] += dp[0][x] + a[x]; dp[1][v] = max(dp[1][v], dp[0][x] + a[x]); } } void dfs2(int v, int p = -1, ll w = 0) { if (max(w, dp[1][v]) < mn) { mn = max(w, dp[1][v]); ans = v; } for (auto& x : adj[v]) { if (x == p) continue; dfs2(x, v, dp[0][v] - dp[0][x] - a[x] + a[v] + w); } } int LocateCentre(int n, int p[], int s[], int d[]) { for (int i = 0;i < n;i++) { a[i] = 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); dfs2(0); 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...