이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "roads.h"
#include<bits/stdc++.h>
#define F first
#define S second
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
ll n,dp[2009][2],k;
vector<vector<pair<ll,ll> > >v;
vector<ll>ans;
void dfs(ll d,ll p)
{
dp[d][0]=dp[d][1]=0;
vector<pair<ll,ll> >op;
for(auto z:v[d])
if(z.F!=p)
{
dfs(z.F,d);
dp[z.F][0]+=z.S;
op.push_back({dp[z.F][0]-dp[z.F][1],z.F});
}
sort(all(op));
ll o=max(0LL,(ll)op.size()-k);
for(ll i=0; i<o; i++)
dp[d][0]+=dp[op[i].S][0];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][0]+=dp[op[i].S][1];
o=max(0LL,(ll)op.size()-k+1);
for(ll i=0; i<o; i++)
dp[d][1]+=dp[op[i].S][0];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][1]+=dp[op[i].S][1];
}
vector<ll>minimum_closure_costs(int N,vector<int> U,vector<int> V,vector<int> W)
{
n=N;
v.resize(n);
ans.resize(n);
for(ll i=0; i<n-1; i++)
{
v[U[i]].push_back({V[i],W[i]});
v[V[i]].push_back({U[i],W[i]});
ans[0]+=W[i];
}
for(k=1; k<n; k++)
{
dfs(0,0);
ans[k]=dp[0][0];
}
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... |