# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1101889 |
2024-10-17T06:49:05 Z |
vjudge1 |
Museum (CEOI17_museum) |
C++17 |
|
3000 ms |
783432 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 10000 + 2;
const int inf = 1 << 28;
int sz[N];
int dp[N][2][N];
vector<pair<int, int>> g[N];
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];
}
for (int i = 0; i <= sz[u]; i++) dp[u][0][i] = dp[u][1][i] = 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';
for (int i = 0; i <= n; i++) {
g[i].clear();
}
}
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 |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
735 ms |
783060 KB |
Output is correct |
2 |
Correct |
1109 ms |
783168 KB |
Output is correct |
3 |
Execution timed out |
3051 ms |
783432 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
735 ms |
783060 KB |
Output is correct |
2 |
Correct |
1109 ms |
783168 KB |
Output is correct |
3 |
Execution timed out |
3051 ms |
783432 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
735 ms |
783060 KB |
Output is correct |
7 |
Correct |
1109 ms |
783168 KB |
Output is correct |
8 |
Execution timed out |
3051 ms |
783432 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |