# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
952037 |
2024-03-23T04:02:19 Z |
vjudge1 |
Museum (CEOI17_museum) |
C++17 |
|
368 ms |
784996 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
354 ms |
784428 KB |
Output is correct |
2 |
Correct |
204 ms |
784100 KB |
Output is correct |
3 |
Correct |
263 ms |
784216 KB |
Output is correct |
4 |
Correct |
210 ms |
784176 KB |
Output is correct |
5 |
Correct |
207 ms |
784204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
784468 KB |
Output is correct |
2 |
Correct |
213 ms |
784464 KB |
Output is correct |
3 |
Correct |
215 ms |
784996 KB |
Output is correct |
4 |
Correct |
212 ms |
784724 KB |
Output is correct |
5 |
Correct |
212 ms |
784468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
216 ms |
784468 KB |
Output is correct |
2 |
Correct |
213 ms |
784464 KB |
Output is correct |
3 |
Correct |
215 ms |
784996 KB |
Output is correct |
4 |
Correct |
212 ms |
784724 KB |
Output is correct |
5 |
Correct |
212 ms |
784468 KB |
Output is correct |
6 |
Correct |
213 ms |
784448 KB |
Output is correct |
7 |
Correct |
214 ms |
784944 KB |
Output is correct |
8 |
Correct |
217 ms |
784512 KB |
Output is correct |
9 |
Correct |
215 ms |
784408 KB |
Output is correct |
10 |
Correct |
212 ms |
784516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
784428 KB |
Output is correct |
2 |
Correct |
204 ms |
784100 KB |
Output is correct |
3 |
Correct |
263 ms |
784216 KB |
Output is correct |
4 |
Correct |
210 ms |
784176 KB |
Output is correct |
5 |
Correct |
207 ms |
784204 KB |
Output is correct |
6 |
Correct |
216 ms |
784468 KB |
Output is correct |
7 |
Correct |
213 ms |
784464 KB |
Output is correct |
8 |
Correct |
215 ms |
784996 KB |
Output is correct |
9 |
Correct |
212 ms |
784724 KB |
Output is correct |
10 |
Correct |
212 ms |
784468 KB |
Output is correct |
11 |
Correct |
213 ms |
784448 KB |
Output is correct |
12 |
Correct |
214 ms |
784944 KB |
Output is correct |
13 |
Correct |
217 ms |
784512 KB |
Output is correct |
14 |
Correct |
215 ms |
784408 KB |
Output is correct |
15 |
Correct |
212 ms |
784516 KB |
Output is correct |
16 |
Correct |
229 ms |
784468 KB |
Output is correct |
17 |
Correct |
286 ms |
784464 KB |
Output is correct |
18 |
Correct |
235 ms |
784724 KB |
Output is correct |
19 |
Correct |
238 ms |
784492 KB |
Output is correct |
20 |
Correct |
234 ms |
784808 KB |
Output is correct |
21 |
Correct |
312 ms |
784720 KB |
Output is correct |
22 |
Correct |
313 ms |
784824 KB |
Output is correct |
23 |
Correct |
368 ms |
784452 KB |
Output is correct |
24 |
Correct |
340 ms |
784468 KB |
Output is correct |
25 |
Correct |
328 ms |
784884 KB |
Output is correct |