Submission #1048004

#TimeUsernameProblemLanguageResultExecution timeMemory
1048004Marco_EscandonRoad Closures (APIO21_roads)C++11
0 / 100
2093 ms27732 KiB
//#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()); for(int i=0; i<min((ll)asd.size(),k-B); i++) c+=asd[i]; return cache[node][B]=c; } 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 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...