답안 #155709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155709 2019-09-30T03:20:48 Z Fischer Museum (CEOI17_museum) C++14
80 / 100
3000 ms 44836 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 2;
struct Node {
	int v, w;
};
vector<Node> g[maxn];
int n, k, x;
int sz[maxn];
int memo[maxn][maxn][2];

void dfs(int x, int p) {
	sz[x] = 1;
	for (auto node : g[x]) {
		if (node.v == p) continue;
		dfs(node.v, x);
		sz[x] += sz[node.v];
	}
	for (int i = 2; i <= min(sz[x], k); ++i) {
		memo[x][i][0] = memo[x][i][1] = 1e9;
	}
	for (auto node : g[x]) {
		if (node.v == p) continue;
		for (int i = min(sz[x], k); i >= 2; --i) {
			for (int j = 1; j <= min(sz[node.v], i-1); ++j) {
				memo[x][i][1] = min(memo[x][i][1],
					min(
						memo[x][i-j][1] + memo[node.v][j][0] + 2*node.w,
						memo[x][i-j][0] + memo[node.v][j][1] + node.w
					));
				memo[x][i][0] = min(memo[x][i][0], 
					memo[x][i-j][0] + memo[node.v][j][0] + 2*node.w);
			}
		}
	}
}

int main() {
	cin >> n >> k >> x;
	for (int i = 1; i <= n-1; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	dfs(x, 0);
	cout << memo[x][k][1] << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 27888 KB Output is correct
2 Correct 52 ms 27768 KB Output is correct
3 Correct 100 ms 34132 KB Output is correct
4 Correct 78 ms 32632 KB Output is correct
5 Correct 68 ms 31224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 27888 KB Output is correct
2 Correct 52 ms 27768 KB Output is correct
3 Correct 100 ms 34132 KB Output is correct
4 Correct 78 ms 32632 KB Output is correct
5 Correct 68 ms 31224 KB Output is correct
6 Correct 48 ms 23032 KB Output is correct
7 Correct 97 ms 32364 KB Output is correct
8 Correct 36 ms 2680 KB Output is correct
9 Correct 35 ms 2680 KB Output is correct
10 Correct 37 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 52 ms 27888 KB Output is correct
7 Correct 52 ms 27768 KB Output is correct
8 Correct 100 ms 34132 KB Output is correct
9 Correct 78 ms 32632 KB Output is correct
10 Correct 68 ms 31224 KB Output is correct
11 Correct 48 ms 23032 KB Output is correct
12 Correct 97 ms 32364 KB Output is correct
13 Correct 36 ms 2680 KB Output is correct
14 Correct 35 ms 2680 KB Output is correct
15 Correct 37 ms 3192 KB Output is correct
16 Correct 138 ms 28376 KB Output is correct
17 Correct 772 ms 28908 KB Output is correct
18 Correct 2246 ms 44836 KB Output is correct
19 Correct 78 ms 2812 KB Output is correct
20 Correct 95 ms 4344 KB Output is correct
21 Execution timed out 3034 ms 21280 KB Time limit exceeded
22 Halted 0 ms 0 KB -