# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
569343 | Edil | 도로 폐쇄 (APIO21_roads) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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+1);
vector <ed> tr(n+1);
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; 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;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n;
cin >> n; n--;
vector <int> u(n), v(n), w(n);
for(int i = 0; i < n; i++)
cin >> u[i] >> v[i] >> w[i];
vector <ll> a;
a = minimum_closure_costs(n, u, v, w);
for(ll i : a)
cout << i << " ";
}