답안 #952163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952163 2024-03-23T07:42:44 Z vjudge1 Museum (CEOI17_museum) C++17
100 / 100
552 ms 759060 KB
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 1e4 + 1;
struct node { int to, cost; };
vector <node> G[N];
int dp[N][N][2], siz[N];
int n, k, x;
inline void dfs(int u, int fa) {
	siz[u] = 1; dp[u][1][0] = dp[u][1][1] = 0;
	for (auto & e : G[u]) {
		int v = e.to;
		if(v == fa) continue;
		dfs(v, u);
		for (int i = min(k, siz[u]); i >= 0; --i) {
			for (int j = 0; j <= min(k - i, siz[v]); ++j) {
				dp[u][i + j][0] = min(dp[u][i + j][0], dp[u][i][0] + dp[v][j][0] + e.cost * 2);
				dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][0] + dp[v][j][1] + e.cost);
				dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][1] + dp[v][j][0] + e.cost * 2);
			}
		}
		siz[u] += siz[v];
	}
}
int main() {
	scanf("%d%d%d", &n, &k, &x);
	for (int i = 1; i < n; ++i) {
		int u, v, w; scanf("%d%d%d", &u, &v, &w);
		G[u].push_back({v, w});
		G[v].push_back({u, w});
	}
	for (int i = 0; i <= n; ++i)
		for	(int j = 0; j <= k; ++j)
			dp[i][j][0] = dp[i][j][1] = 1e8;
	dfs(x, -1);
	printf("%d", min(dp[x][k][0], dp[x][k][1]));
	return 0;
}

Compilation message

museum.cpp: In function 'int main()':
museum.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d%d%d", &n, &k, &x);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
museum.cpp:28:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |   int u, v, w; scanf("%d%d%d", &u, &v, &w);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 288824 KB Output is correct
2 Correct 46 ms 288624 KB Output is correct
3 Correct 48 ms 289104 KB Output is correct
4 Correct 49 ms 288852 KB Output is correct
5 Correct 47 ms 288584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 288824 KB Output is correct
2 Correct 46 ms 288624 KB Output is correct
3 Correct 48 ms 289104 KB Output is correct
4 Correct 49 ms 288852 KB Output is correct
5 Correct 47 ms 288584 KB Output is correct
6 Correct 49 ms 294484 KB Output is correct
7 Correct 49 ms 292728 KB Output is correct
8 Correct 53 ms 292692 KB Output is correct
9 Correct 56 ms 294736 KB Output is correct
10 Correct 51 ms 292692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 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 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 136 ms 288824 KB Output is correct
7 Correct 46 ms 288624 KB Output is correct
8 Correct 48 ms 289104 KB Output is correct
9 Correct 49 ms 288852 KB Output is correct
10 Correct 47 ms 288584 KB Output is correct
11 Correct 49 ms 294484 KB Output is correct
12 Correct 49 ms 292728 KB Output is correct
13 Correct 53 ms 292692 KB Output is correct
14 Correct 56 ms 294736 KB Output is correct
15 Correct 51 ms 292692 KB Output is correct
16 Correct 88 ms 339796 KB Output is correct
17 Correct 246 ms 548944 KB Output is correct
18 Correct 94 ms 339700 KB Output is correct
19 Correct 133 ms 339720 KB Output is correct
20 Correct 90 ms 339620 KB Output is correct
21 Correct 462 ms 759060 KB Output is correct
22 Correct 462 ms 758612 KB Output is correct
23 Correct 552 ms 758552 KB Output is correct
24 Correct 374 ms 758608 KB Output is correct
25 Correct 422 ms 759020 KB Output is correct