Submission #988749

#TimeUsernameProblemLanguageResultExecution timeMemory
988749noyancanturkMuseum (CEOI17_museum)C++17
100 / 100
523 ms792276 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back const int lim=10100; const int mod=1e9+7; using pii=pair<int,int>; vector<pii>v[lim]; int sz[lim]; int dp[2][lim][lim]; void dfs(int node,int par){ sz[node]=1; for(int i=0;i<lim;i++){ dp[0][node][i]=dp[1][node][i]=1e9+1; } dp[0][node][1]=dp[1][node][1]=0; for(auto[child,c]:v[node]){ if(child==par)continue; dfs(child,node); for(int i=sz[node];i;i--){ for(int j=1;j<=sz[child];j++){ dp[0][node][i+j]=min(dp[0][node][i+j],dp[0][node][i]+dp[0][child][j]+2*c); dp[1][node][i+j]=min( { dp[1][node][i+j], dp[0][node][i]+dp[1][child][j]+c, dp[1][node][i]+dp[0][child][j]+2*c } ); } } sz[node]+=sz[child]; } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Local freopen(".in","r",stdin);freopen(".out","w",stdout); #endif int n,k,x; cin>>n>>k>>x; for(int i=0;i<n-1;i++){ int X,Y,Z; cin>>X>>Y>>Z; v[X].pb({Y,Z}); v[Y].pb({X,Z}); } dfs(x,0); cout<<dp[1][x][k]<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...