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 "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][1]-dp[z.F][0],z.F});
}
sort(all(op));
ll o=min((ll)op.size(),k);
for(ll i=0; i<o; i++)
dp[d][0]+=dp[op[i].S][1];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][0]+=dp[op[i].S][0];
o=min((ll)op.size(),k-1);
for(ll i=0; i<o; i++)
dp[d][1]+=dp[op[i].S][1];
for(ll i=o; i<(ll)op.size(); i++)
dp[d][1]+=dp[op[i].S][0];
}
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,-1);
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... |