# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
864016 |
2023-10-21T16:57:01 Z |
sheldon |
Museum (CEOI17_museum) |
C++14 |
|
387 ms |
784800 KB |
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e4 + 5;
int dp[nax][nax][2], sz[nax];
vector<pair<int, int>> edges[nax];
void dfs (int u, int p) {
sz[u] = 1;
for (pair<int, int> pp : edges[u]) {
int v = pp.first, c = pp.second;
if (v != p) {
dfs (v, u);
for (int i = sz[u]; i >= 1; --i) {
for (int j = 1; j <= sz[v]; ++j) {
dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][0] + dp[v][j][1] + c);
dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][1] + dp[v][j][0] + c * 2);
dp[u][i + j][0] = min(dp[u][i + j][0], dp[u][i][0] + dp[v][j][0] + c * 2);
}
}
sz[u] += sz[v];
}
}
}
void solve() {
int n, k, x;
cin >> n >> k >> x;
for (int i = 0; i < n - 1; ++i) {
int u, v, c;
cin >> u >> v >> c;
edges[u].push_back({v, c});
edges[v].push_back({u, c});
}
for (int i = 1; i <= n; ++i) {
for (int j = 2; j <= n; ++j) {
dp[i][j][0] = dp[i][j][1] = 1e9;
}
}
dfs (x, 0);
cout << dp[x][k][1];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
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 |
2652 KB |
Output is correct |
5 |
Correct |
0 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
784320 KB |
Output is correct |
2 |
Correct |
370 ms |
784604 KB |
Output is correct |
3 |
Correct |
357 ms |
784800 KB |
Output is correct |
4 |
Correct |
344 ms |
784596 KB |
Output is correct |
5 |
Correct |
374 ms |
784388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
784320 KB |
Output is correct |
2 |
Correct |
370 ms |
784604 KB |
Output is correct |
3 |
Correct |
357 ms |
784800 KB |
Output is correct |
4 |
Correct |
344 ms |
784596 KB |
Output is correct |
5 |
Correct |
374 ms |
784388 KB |
Output is correct |
6 |
Correct |
363 ms |
784720 KB |
Output is correct |
7 |
Correct |
358 ms |
784548 KB |
Output is correct |
8 |
Correct |
387 ms |
784464 KB |
Output is correct |
9 |
Correct |
360 ms |
784460 KB |
Output is correct |
10 |
Correct |
342 ms |
784464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
2652 KB |
Output is correct |
5 |
Correct |
0 ms |
2652 KB |
Output is correct |
6 |
Correct |
371 ms |
784320 KB |
Output is correct |
7 |
Correct |
370 ms |
784604 KB |
Output is correct |
8 |
Correct |
357 ms |
784800 KB |
Output is correct |
9 |
Correct |
344 ms |
784596 KB |
Output is correct |
10 |
Correct |
374 ms |
784388 KB |
Output is correct |
11 |
Correct |
363 ms |
784720 KB |
Output is correct |
12 |
Correct |
358 ms |
784548 KB |
Output is correct |
13 |
Correct |
387 ms |
784464 KB |
Output is correct |
14 |
Correct |
360 ms |
784460 KB |
Output is correct |
15 |
Correct |
342 ms |
784464 KB |
Output is correct |
16 |
Correct |
341 ms |
784504 KB |
Output is correct |
17 |
Correct |
342 ms |
784452 KB |
Output is correct |
18 |
Correct |
358 ms |
784472 KB |
Output is correct |
19 |
Correct |
351 ms |
784340 KB |
Output is correct |
20 |
Correct |
345 ms |
784656 KB |
Output is correct |
21 |
Correct |
342 ms |
784468 KB |
Output is correct |
22 |
Correct |
345 ms |
784276 KB |
Output is correct |
23 |
Correct |
352 ms |
784468 KB |
Output is correct |
24 |
Correct |
344 ms |
784544 KB |
Output is correct |
25 |
Correct |
346 ms |
784748 KB |
Output is correct |