제출 #1048007

#제출 시각아이디문제언어결과실행 시간메모리
1048007Marco_Escandon도로 폐쇄 (APIO21_roads)C++11
31 / 100
2100 ms33620 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()); 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 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...