이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "roads.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
ll n;
vector<vector<pair<ll,ll>>> cad;
ll k;
vector<vector<ll>> cache;
ll sol(ll node,ll B, ll P)
{
if(B>k) return 1e14;
if(cache[node][B]!=-1) return cache[node][B];
vector<ll> asd;
ll c=0;
for(auto i:cad[node])
{
if(i.x==P) continue;
ll o1=sol(i.x,1,node);
ll o2=i.y+sol(i.x,0,node);
c+=o2;
asd.push_back(o1-o2);
}
if(asd.size()==0) return cache[node][B]=0;
sort(asd.begin(),asd.end());
ll a=c;
for(int i=0; i<min((ll)asd.size(),k-B); i++)
{
c+=asd[i];
a=min(c,a);
}
return cache[node][B]=a;
}
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,std::vector<int> V,std::vector<int> W) {
n=N;
cad.resize(n+1);
for(int i=0; i<n-1; i++)
{
cad[U[i]].push_back({V[i],W[i]});
cad[V[i]].push_back({U[i],W[i]});
}
vector<ll> s(n,0);
for(int i=0; i<n; i++)
{
k=i;
cache.assign(n,{-1,-1});
s[i]=sol(0,0,-1);
if(s[i]==0) break;
}
return s;
}
# | 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... |