Submission #1114455

#TimeUsernameProblemLanguageResultExecution timeMemory
1114455vladiliusRoad Closures (APIO21_roads)C++17
0 / 100
736 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second vector<ll> minimum_closure_costs(int n, vector<int> U, vector<int> V, vector<int> W){ vector<pii> g[n + 1]; ll tot = 0; for (int i = 0; i < n - 1; i++){ int u = U[i] + 1, v = V[i] + 1, w = W[i]; g[u].pb({v, w}); g[v].pb({u, w}); tot += w; } vector<vector<ll>> dp(n + 1, vector<ll>(n)); function<void(int, int)> dfs = [&](int v, int pr){ for (auto [i, w]: g[v]){ if (i == pr) continue; dfs(i, v); } for (int k = 1; k < n; k++){ dp[v][k] = 0; vector<ll> all; for (auto [i, w]: g[v]){ if (i == pr) continue; dp[v][k] += dp[i][k]; all.pb(dp[i][k - 1] - dp[i][k] + w); } sort(all.begin(), all.end(), greater<ll>()); for (int j = 0; j < min((int) all.size(), k); j++){ if (all[j] <= 0) break; dp[v][k] += all[j]; } } for (int k = 1; k < n; k++){ dp[v][k] = max(dp[v][k], dp[v][k - 1]); } }; dfs(1, 0); vector<ll> out; for (int i = 0; i < n; i++){ out.pb(tot - dp[1][i]); } return out; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...