# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569493 | Turkhuu | Road Closures (APIO21_roads) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "roads.h"
#include <bits/stdc++.h>
std::vector<long long> minimum_closure_costs(int n, std::vector<int> u, std::vector<int> v, std::vector<int> w){
bool subtask1 = true;
for(int i = 0; i < n - 1; i++){
if(u[i] != 0){
subtask1 = false;
}
}
if(subtask1){
sort(w.begin(), w.end());
std::vector<long long> ans(n);
for(int i = 0; i < n - 1; i++){
ans[n - i - 2] = ans[n - i - 1] + w[i];
}
return ans;
}
bool subtask2 = true;
for(int i = 0; i < n - 1; i++){
if(u[i] != i || v[i] != i + 1){
subtask2 = false;
}
}
if(subtask2){
std::assert(false);
std::vector<long long> ans(n);
ans[0] = accumulate(w.begin(), w.end(), 0LL);
std::vector<std::vector<long long>> dp(n, std::vector<long long>(2));
for(int i = 0; i < n - 1; i++){
dp[i][0] = (i == 0 ? 0 : std::min(dp[i - 1][0], dp[i - 1][1])) + w[i];
dp[i][1] = (i == 0 ? 0 : dp[i - 1][0]) + w[i];
}
ans[1] = std::min(dp.back()[0], dp.back()[1]);
return ans;
}
return std::vector<long long>(n, 0);
}