Submission #952037

#TimeUsernameProblemLanguageResultExecution timeMemory
952037vjudge1Museum (CEOI17_museum)C++17
100 / 100
368 ms784996 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN=1e4+5; int n,k,x,inu,inv,inw,dp[MAXN][MAXN][2],siz[MAXN],minn=INT_MAX; vector <pair<int,int> > lis[MAXN]; void dfs(int u,int fa){ dp[u][1][0]=0; dp[u][1][1]=0; siz[u]=1; for(auto it:lis[u]){ int v=it.first; int w=it.second; if(v==fa) continue; dfs(v,u); for(int i=min(siz[u],k);i>=1;i--) for(int j=1;j<=min(siz[v],k-i);j++){ //if(i-j-2){ dp[u][i+j][0]=min(dp[u][i+j][0],dp[u][i][0]+dp[v][j][0]+w*2); dp[u][i+j][1]=min(dp[u][i+j][1],dp[u][i][1]+dp[v][j][0]+w*2); dp[u][i+j][1]=min(dp[u][i+j][1],dp[u][i][0]+dp[v][j][1]+w); } siz[u]+=siz[v]; } } int main(){ // freopen("museum.in","r",stdin); // freopen("museum.out","w",stdout); scanf("%d%d%d",&n,&k,&x); for(int i=1;i<n;i++){ scanf("%d%d%d",&inu,&inv,&inw); lis[inu].push_back({inv,inw}); lis[inv].push_back({inu,inw}); } memset(dp,0x3f,sizeof dp); dfs(x,-1); /* for(int i=1;i<=n;i++){ printf("I%d\n",i); for(int j=1;j<=k;j++) printf("%d %d ",dp[i][j][0],dp[i][j][1]); printf("\n"); }*/ printf("%d",min(dp[x][k][0],dp[x][k][1])); }

Compilation message (stderr)

museum.cpp: In function 'int main()':
museum.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  scanf("%d%d%d",&n,&k,&x);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
museum.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d%d%d",&inu,&inv,&inw);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...