제출 #1223388

#제출 시각아이디문제언어결과실행 시간메모리
1223388SpyrosAlivRoad Closures (APIO21_roads)C++20
0 / 100
526 ms1114112 KiB
#include "roads.h" using namespace std; #define ll long long const ll INF = 1e17; vector<vector<pair<int, ll>>> tree; vector<vector<ll>> dp; int n; void dfs(int node, int par = 0) { for (auto [next, w]: tree[node]) { if (next == par) continue; dfs(next, node); } for (int k = 0; k <= n; k++) { ll ans = 0; if (k == 0) { for (auto [next, w]: tree[node]) { if (next == par) continue; ans += w; } dp[node][k] = ans; continue; } vector<ll> ops; for (auto [next, w]: tree[node]) { if (next == par) continue; ops.push_back(dp[next][k] - (dp[next][k-1] + w)); ans += dp[next][k-1] + w; } sort(ops.begin(), ops.end()); if (ops.size() < k) { break; } for (int j = 0; j < k; j++) { ans += ops[j]; } dp[node][k] = ans; } } vector<ll> minimum_closure_costs(int N, vector<int> U, vector<int> V, vector<int> W) { n = N; tree.resize(n+1); for (int i = 0; i < n; i++) { U[i]++; V[i]++; tree[U[i]].push_back({V[i], W[i]}); tree[V[i]].push_back({U[i], W[i]}); } dp.assign(n+1, vector<ll>(n+1, INF)); dfs(1); vector<ll> ans; for (int k = 1; k <= n; k++) dp[1][k] = min(dp[1][k], dp[1][k-1]); for (int k = 0; k <= n; k++) ans.push_back(dp[1][k]); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...