# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
202103 |
2020-02-13T21:36:44 Z |
thebes |
Museum (CEOI17_museum) |
C++14 |
|
867 ms |
784928 KB |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
const int MN = 1e4+5;
int N, K, X, i, j, x, y, w, dp[MN][MN], dp2[MN][MN], tmp[MN], tmp2[MN], sz[MN];
vector<pii> adj[MN];
void dfs(int n,int p){
memset(dp[n],0x3f,sizeof(dp[n]));
memset(dp2[n],0x3f,sizeof(dp2[n]));
dp[n][0]=dp[n][1]=dp2[n][0]=dp2[n][1]=0;
sz[n] = 1;
for(auto v : adj[n]){
if(v.first==p) continue;
dfs(v.first, n);
memset(tmp,0x3f,sizeof(tmp));
memset(tmp2,0x3f,sizeof(tmp2));
for(i=0;i<=sz[n];i++){
for(j=0;j<=sz[v.first];j++){
tmp[i+j]=min(tmp[i+j],dp[n][i]+dp[v.first][j]+2*v.second);
tmp2[i+j]=min(tmp2[i+j],min(dp[n][i]+dp2[v.first][j]+v.second,dp2[n][i]+dp[v.first][j]+2*v.second));
}
}
sz[n] += sz[v.first];
for(i=0;i<=sz[n];i++){
dp[n][i]=min(dp[n][i],tmp[i]);
dp2[n][i]=min(dp2[n][i],tmp2[i]);
}
}
}
int main(){
scanf("%d%d%d",&N,&K,&X);
for(i=1;i<N;i++){
scanf("%d%d%d",&x,&y,&w);
adj[x].pb({y,w});
adj[y].pb({x,w});
}
dfs(X,0);
printf("%d\n",min(dp[X][K],dp2[X][K]));
return 0;
}
Compilation message
museum.cpp: In function 'int main()':
museum.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&N,&K,&X);
~~~~~^~~~~~~~~~~~~~~~~~~
museum.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&x,&y,&w);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2168 KB |
Output is correct |
2 |
Correct |
6 ms |
2296 KB |
Output is correct |
3 |
Correct |
6 ms |
2168 KB |
Output is correct |
4 |
Correct |
6 ms |
2168 KB |
Output is correct |
5 |
Correct |
6 ms |
2168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
867 ms |
784504 KB |
Output is correct |
2 |
Correct |
598 ms |
784376 KB |
Output is correct |
3 |
Correct |
701 ms |
784928 KB |
Output is correct |
4 |
Correct |
619 ms |
784504 KB |
Output is correct |
5 |
Correct |
596 ms |
784504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
867 ms |
784504 KB |
Output is correct |
2 |
Correct |
598 ms |
784376 KB |
Output is correct |
3 |
Correct |
701 ms |
784928 KB |
Output is correct |
4 |
Correct |
619 ms |
784504 KB |
Output is correct |
5 |
Correct |
596 ms |
784504 KB |
Output is correct |
6 |
Correct |
594 ms |
784304 KB |
Output is correct |
7 |
Correct |
651 ms |
784636 KB |
Output is correct |
8 |
Correct |
850 ms |
784504 KB |
Output is correct |
9 |
Correct |
773 ms |
784376 KB |
Output is correct |
10 |
Correct |
635 ms |
784376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2168 KB |
Output is correct |
2 |
Correct |
6 ms |
2296 KB |
Output is correct |
3 |
Correct |
6 ms |
2168 KB |
Output is correct |
4 |
Correct |
6 ms |
2168 KB |
Output is correct |
5 |
Correct |
6 ms |
2168 KB |
Output is correct |
6 |
Correct |
867 ms |
784504 KB |
Output is correct |
7 |
Correct |
598 ms |
784376 KB |
Output is correct |
8 |
Correct |
701 ms |
784928 KB |
Output is correct |
9 |
Correct |
619 ms |
784504 KB |
Output is correct |
10 |
Correct |
596 ms |
784504 KB |
Output is correct |
11 |
Correct |
594 ms |
784304 KB |
Output is correct |
12 |
Correct |
651 ms |
784636 KB |
Output is correct |
13 |
Correct |
850 ms |
784504 KB |
Output is correct |
14 |
Correct |
773 ms |
784376 KB |
Output is correct |
15 |
Correct |
635 ms |
784376 KB |
Output is correct |
16 |
Correct |
596 ms |
784376 KB |
Output is correct |
17 |
Correct |
588 ms |
784436 KB |
Output is correct |
18 |
Correct |
621 ms |
784504 KB |
Output is correct |
19 |
Correct |
770 ms |
784376 KB |
Output is correct |
20 |
Correct |
612 ms |
784376 KB |
Output is correct |
21 |
Correct |
640 ms |
784604 KB |
Output is correct |
22 |
Correct |
600 ms |
784376 KB |
Output is correct |
23 |
Correct |
769 ms |
784376 KB |
Output is correct |
24 |
Correct |
601 ms |
784504 KB |
Output is correct |
25 |
Correct |
680 ms |
784884 KB |
Output is correct |