Submission #1005416

#TimeUsernameProblemLanguageResultExecution timeMemory
10054160npataRoad Closures (APIO21_roads)C++17
0 / 100
88 ms68936 KiB
#include "roads.h" #include<bits/stdc++.h> using namespace std; #define vec vector #define int long long const int MXN = 2'005; vec<pair<int, int>> tree[MXN]; int dp[MXN][MXN]; void dfs(int u, int p = -1) { for(auto [v, w] : tree[u]) { if(v == p) continue; dfs(v, u); } for(int k = 1; k<MXN; k++) { vec<int> ext(0); for(auto [v, w] : tree[u]) { if(v == p) continue; dp[u][k] += dp[v][k]; ext.push_back(w + dp[v][k-1] - dp[v][k]); } sort(ext.begin(), ext.end(), greater<int>()); for(int i = 0; i<min((int) ext.size(), k); i++) { if(ext[i] > 0) dp[u][k] += ext[i]; } } } std::vector<int> minimum_closure_costs(int32_t n, std::vector<int32_t> u, std::vector<int32_t> v, std::vector<int32_t> w) { for(int i = 0; i<MXN; i++) { tree[i] = {}; for(int j = 0; j<MXN; j++) { dp[i][j] = 0; } } int sumw = 0; for(int i = 0; i<n-1; i++) { tree[u[i]].push_back({v[i], w[i]}); tree[v[i]].push_back({u[i], w[i]}); sumw += w[i]; } dfs(0); vec<int> ans(n); for(int i = 0; i<n; i++) { ans[i] = sumw - dp[0][i]; } 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...