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>
using namespace std;
const int dydis = 1e5 + 10;
vector<pair<int, int> > gr[dydis];
int n, m;
vector<long long> minimum_closure_costs(int N, std::vector<int> U,
std::vector<int> V,
std::vector<int> W) {
n = N; m = W.size();
bool line = true, star = true;
vector<int> mas;
for(int i = 0; i < m; i++) {
int a = U[i]; int b = V[i]; int w = W[i];
if(a != b-1) line = false;
if(a != 0) star = false;
gr[a].push_back({b, w});
gr[b].push_back({a, w});
mas.push_back(w);
}
if(line) {
/// Galiu praleisti max 1 is eiles. Kokia min suma?
long long dp[n]; /// dp[i] - turiu visus iki i ir i-aji emiau. Kokia min suma?
dp[0] = mas[0];
dp[1] = mas[1];
for(int i = 2; i < n; i++) {
dp[i] = min(dp[i-1] + mas[i], dp[i-2] + mas[i]);
}
vector<long long> ret(n, 0);
for(auto x : mas) ret[0] += x;
ret[1] = min(dp[n-1], dp[n-2]);
return ret;
}
if(star) {
//cout << "star - " << true << endl;
sort(mas.begin(), mas.end());
reverse(mas.begin(), mas.end());
vector<long long> ret(n, 0);
for(auto x : mas) ret[0] += x;
long long sum = 0;
for(int i = n-1; i > 0; i--) {
if(i != n- 1) sum += mas[i];
ret[i] = sum;
}
return ret;
}
return vector<long long>(N, 0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |