Submission #1005412

#TimeUsernameProblemLanguageResultExecution timeMemory
10054120npataRoad Closures (APIO21_roads)C++17
0 / 100
102 ms6524 KiB
#include "roads.h" #include<bits/stdc++.h> using namespace std; #define vec vector #define int long long const int N = 2'005; vec<pair<int, int>> tree[N]; int dp[N][N]; 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<N; 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) { 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...