# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1095005 |
2024-10-01T07:09:49 Z |
blackslex |
Museum (CEOI17_museum) |
C++17 |
|
865 ms |
786256 KB |
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n, k, c, x, y, z;
int main() {
scanf("%d %d %d", &n, &k, &c);
vector<int> sz(n + 5, 1);
vector<vector<pii>> v(n + 5, vector<pii>());
vector<vector<vector<int>>> dp(n + 5, vector<vector<int>>(2, vector<int>(n + 5, 1e9)));
for (int i = 1; i < n; i++) {
scanf("%d %d %d", &x, &y, &z);
v[x].emplace_back(y, z); v[y].emplace_back(x, z);
}
function<void(int, int)> dfs = [&] (int cur, int par) {
for (auto i: {0, 1}) {
for (auto j: {0, 1}) dp[cur][i][j] = 0;
}
for (auto &[x, y]: v[cur]) {
if (par == x) continue;
dfs(x, cur);
for (int i = sz[cur]; ~i; i--) {
for (int j = sz[x]; ~j; j--) {
dp[cur][0][i + j] = min(dp[cur][0][i + j], dp[cur][1][i] + dp[x][0][j] + y);
dp[cur][0][i + j] = min(dp[cur][0][i + j], dp[cur][0][i] + dp[x][1][j] + y * 2);
dp[cur][1][i + j] = min(dp[cur][1][i + j], dp[cur][1][i] + dp[x][1][j] + y * 2);
}
}
sz[cur] += sz[x];
}
};
dfs(c, 0);
printf("%d", min(dp[c][0][k], dp[c][1][k]));
}
Compilation message
museum.cpp: In function 'int main()':
museum.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | scanf("%d %d %d", &n, &k, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d %d %d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
487 ms |
785744 KB |
Output is correct |
2 |
Correct |
489 ms |
785740 KB |
Output is correct |
3 |
Correct |
576 ms |
786256 KB |
Output is correct |
4 |
Correct |
521 ms |
785792 KB |
Output is correct |
5 |
Correct |
497 ms |
785736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
487 ms |
785744 KB |
Output is correct |
2 |
Correct |
489 ms |
785740 KB |
Output is correct |
3 |
Correct |
576 ms |
786256 KB |
Output is correct |
4 |
Correct |
521 ms |
785792 KB |
Output is correct |
5 |
Correct |
497 ms |
785736 KB |
Output is correct |
6 |
Correct |
493 ms |
785660 KB |
Output is correct |
7 |
Correct |
580 ms |
786004 KB |
Output is correct |
8 |
Correct |
865 ms |
785884 KB |
Output is correct |
9 |
Correct |
727 ms |
785804 KB |
Output is correct |
10 |
Correct |
571 ms |
785688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
487 ms |
785744 KB |
Output is correct |
7 |
Correct |
489 ms |
785740 KB |
Output is correct |
8 |
Correct |
576 ms |
786256 KB |
Output is correct |
9 |
Correct |
521 ms |
785792 KB |
Output is correct |
10 |
Correct |
497 ms |
785736 KB |
Output is correct |
11 |
Correct |
493 ms |
785660 KB |
Output is correct |
12 |
Correct |
580 ms |
786004 KB |
Output is correct |
13 |
Correct |
865 ms |
785884 KB |
Output is correct |
14 |
Correct |
727 ms |
785804 KB |
Output is correct |
15 |
Correct |
571 ms |
785688 KB |
Output is correct |
16 |
Correct |
475 ms |
785744 KB |
Output is correct |
17 |
Correct |
476 ms |
785744 KB |
Output is correct |
18 |
Correct |
515 ms |
786000 KB |
Output is correct |
19 |
Correct |
779 ms |
785716 KB |
Output is correct |
20 |
Correct |
514 ms |
785936 KB |
Output is correct |
21 |
Correct |
569 ms |
786000 KB |
Output is correct |
22 |
Correct |
515 ms |
785864 KB |
Output is correct |
23 |
Correct |
736 ms |
785748 KB |
Output is correct |
24 |
Correct |
480 ms |
785744 KB |
Output is correct |
25 |
Correct |
567 ms |
786232 KB |
Output is correct |