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>
using namespace std;
#define ll long long
#define vct vector <int>
struct ed
{
ll x = 0;
set <ll> y;
};
bool cmp(ed a, ed b)
{
if(a.x == b.x)
return a.y > b.y;
return a.x > b.x;
}
vector <ll> minimum_closure_costs(int n, vct u, vct v, vct w)
{
ll sm = 0;
vector <ll> ans(n);
vector <ed> tr(n);
for(ll i = 0; i < (ll)w.size(); i++)
{
tr[u[i]].x++;
tr[v[i]].x++;
tr[u[i]].y.insert(w[i]);
tr[v[i]].y.insert(w[i]);
sm += w[i];
}
ans[0] = sm;
sm = 0;
sort(tr.begin(), tr.end(), cmp);
for(ll k = n-1; k > 0; k--)
{
ll sm2 = sm;
sm = 0;
for(ll i = 0; tr[i].x > k; i++)
{
tr[i].x--;
sm += *tr[i].y.begin();
tr[i].y.erase(tr[i].y.begin());
}
ans[k] = sm + sm2;
}
return ans;
}
# | 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... |