Submission #1101813

# Submission time Handle Problem Language Result Execution time Memory
1101813 2024-10-16T21:16:08 Z vjudge1 Museum (CEOI17_museum) C++17
20 / 100
3000 ms 14140 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 10000 + 2;
const int inf = 1 << 28;
int sz[N];
vector<pair<int, int>> g[N];
vector<int> dp[N][2];
void calc_dp(int u, int p) {
	sz[u] = 1;
	for (auto [v, c]: g[u]) {
		if (v == p) continue;
		calc_dp(v, u);
		sz[u] += sz[v]; 
	}
	dp[u][0].resize(sz[u] + 1, inf);
	dp[u][1].resize(sz[u] + 1, inf);
	int len = 1;
	dp[u][0][0] = dp[u][1][0] = 0;
	dp[u][0][1] = dp[u][1][1] = 0;
	for (auto [v, c]: g[u]) {
		if (v == p) continue;
		len += sz[v];
		for (int i = len; i >= 0; i--) {
			for (int j = 0; j <= min(i, sz[v]); j++) {
				dp[u][0][i] = min(dp[u][0][i], dp[u][1][i - j] + dp[v][0][j] + c);
				dp[u][0][i] = min(dp[u][0][i], dp[u][0][i - j] + dp[v][1][j] + c + c);
				dp[u][1][i] = min(dp[u][1][i], dp[u][1][i - j] + dp[v][1][j] + c + c);
			}
		}
	}
}
void solve() {
	int n, k, x;
	cin >> n >> k >> x;
	for (int i = 2; i <= n; i++) {
		int u, v, c;
		cin >> u >> v >> c;
		g[u].push_back({v, c});
		g[v].push_back({u, c});
	}
	calc_dp(x, 0);
	cout << dp[x][0][k] << '\n';
	// cout << "Ei porjonto thik ache" << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1360 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 923 ms 3916 KB Output is correct
2 Correct 1398 ms 4052 KB Output is correct
3 Execution timed out 3055 ms 14140 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 923 ms 3916 KB Output is correct
2 Correct 1398 ms 4052 KB Output is correct
3 Execution timed out 3055 ms 14140 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1360 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 923 ms 3916 KB Output is correct
7 Correct 1398 ms 4052 KB Output is correct
8 Execution timed out 3055 ms 14140 KB Time limit exceeded
9 Halted 0 ms 0 KB -