# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1056151 | Muhammet | 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 <bits/stdc++.h>
#include "roads.h"
#include "grader.cpp"
using namespace std;
#define ll long long
#define ff first
#define ss second
vector<ll> minimum_closure_costs(int n, vector<int> u, vector<int> u1, vector<int> w) {
vector <pair<ll,pair<ll,ll>>> v;
ll s = 0;
bool tr = 0;
for(int i = 0; i < n-1; i++){
v.push_back({w[i],{u[i],u1[i]}});
if(u1[i] != u[i]+1) tr = 1;
s += w[i];
}
vector <ll> p(n), p1(n), v1;
for(int i = 0; i < n; i++){
p1[u[i]]++;
p1[u1[i]]++;
}
sort(v.rbegin(), v.rend());
if(*max_element(u.begin(), u.end()) == 0){
ll s2 = s;
v1.push_back(s);
for(int i = 0; i < n-1; i++){
s2 -= (v[i].ff);
v1.push_back(s2);
}
return v1;
}
if(tr == 0){
v1.push_back(s);
if(n >= 3){
vector <ll> p1(n), p2(n);
for(int i = 0; i < n-1; i++){
if(i > 0) p1[i] = p1[i-1], p2[i] = p2[i-1];
if(i % 2 == 0) p2[i] += w[i];
else p1[i] += w[i];
}
ll mx = max(p1[n-2],p2[n-2]);
for(int i = 0; i < n-2; i++){
mx = max(mx,p1[i]+p2[n-2]-p2[i]);
mx = max(mx,p2[i]+p1[n-2]-p1[i]);
}
v1.push_back(s-mx);
for(int i = 2; i < n-1; i++) v1.push_back(0);
return v1;
}
}
for(int i = 0; i < n; i++){
// p = p1;
p.clear();
ll s1 = s;
for(auto j : v){
if(p[j.ss.ff] < i and p[j.ss.ss] < i){
s1 -= j.ff;
p[j.ss.ff]++;
p[j.ss.ss]++;
}
}
v1.push_back(s1);
}
return v1;
}