Submission #485395

#TimeUsernameProblemLanguageResultExecution timeMemory
485395MOUF_MAHMALATRoad Closures (APIO21_roads)C++14
24 / 100
265 ms21572 KiB
#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]+=min(dp[op[i].S][1],dp[op[i].S][0]); 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]+=min(dp[op[i].S][1],dp[op[i].S][0]); 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,0); 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...