답안 #951996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
951996 2024-03-23T03:33:11 Z vjudge1 Museum (CEOI17_museum) C++17
80 / 100
3000 ms 785060 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);
		siz[u]+=siz[v];
		for(int i=min(siz[u],k);i>=1;i--)
			for(int j=1;j<=min(siz[v],i-1);j++){
				//if(i-j-2){
					dp[u][i][0]=min(dp[u][i][0],dp[u][i-j][0]+dp[v][j][0]+w*2);
					dp[u][i][1]=min(dp[u][i][1],dp[u][i-j][1]+dp[v][j][0]+w*2);
					dp[u][i][1]=min(dp[u][i][1],dp[u][i-j][0]+dp[v][j][1]+w);
			}
		
	}
}
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});
	}
for(int i=1;i<=n;i++)
for(int j=0;j<=n;j++)
dp[i][j][0]=dp[i][j][1]=0x3f3f3f3f;
	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);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2676 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 784284 KB Output is correct
2 Correct 271 ms 784468 KB Output is correct
3 Correct 303 ms 785060 KB Output is correct
4 Correct 286 ms 784372 KB Output is correct
5 Correct 289 ms 784324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 345 ms 784284 KB Output is correct
2 Correct 271 ms 784468 KB Output is correct
3 Correct 303 ms 785060 KB Output is correct
4 Correct 286 ms 784372 KB Output is correct
5 Correct 289 ms 784324 KB Output is correct
6 Correct 269 ms 784216 KB Output is correct
7 Correct 301 ms 784524 KB Output is correct
8 Correct 271 ms 784268 KB Output is correct
9 Correct 268 ms 784464 KB Output is correct
10 Correct 274 ms 784268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2676 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 345 ms 784284 KB Output is correct
7 Correct 271 ms 784468 KB Output is correct
8 Correct 303 ms 785060 KB Output is correct
9 Correct 286 ms 784372 KB Output is correct
10 Correct 289 ms 784324 KB Output is correct
11 Correct 269 ms 784216 KB Output is correct
12 Correct 301 ms 784524 KB Output is correct
13 Correct 271 ms 784268 KB Output is correct
14 Correct 268 ms 784464 KB Output is correct
15 Correct 274 ms 784268 KB Output is correct
16 Correct 331 ms 784488 KB Output is correct
17 Correct 854 ms 784484 KB Output is correct
18 Correct 2045 ms 784764 KB Output is correct
19 Correct 299 ms 784320 KB Output is correct
20 Correct 300 ms 784408 KB Output is correct
21 Execution timed out 3080 ms 784468 KB Time limit exceeded
22 Halted 0 ms 0 KB -