# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
952003 |
2024-03-23T03:36:49 Z |
vjudge1 |
Museum (CEOI17_museum) |
C++17 |
|
294 ms |
350484 KB |
#include <stdio.h>
#include <vector>
int n, k, x;
int dp[10005][10005][2];
std::vector<std::pair<int, int> > vec[10005];
int dfs(int, int);
int main()
{
// freopen("museum.in", "r", stdin);
// freopen("museum.out", "w", stdout);
scanf("%d%d%d", &n, &k, &x);
for(int i = 1, a, b, c; i < n; ++i)
{
scanf("%d%d%d", &a, &b, &c);
vec[a].push_back({b, c});
vec[b].push_back({a, c});
}
dfs(x, 0);
printf("%d\n", dp[x][k][1]);
return 0;
}
int dfs(int root, int fa)
{
int siz = 1;
for(auto v : vec[root])
if(v.first != fa)
{
int p = dfs(v.first, root);
for(int i = siz + 1; i <= siz + p; ++i)
dp[root][i][0] = dp[root][i][1] = 0x7f7f7f7f;
for(int i = std::min(siz + p, k); i >= 0; --i)
for(int j = std::max(0, i - siz); j <= p && j <= i; ++j)
{
dp[root][i][1] = std::min(dp[root][i][1], dp[root][i - j][0] + dp[v.first][j][1] + v.second);
dp[root][i][1] = std::min(dp[root][i][1], dp[root][i - j][1] + dp[v.first][j][0] + (v.second << 1));
dp[root][i][0] = std::min(dp[root][i][0], dp[root][i - j][0] + dp[v.first][j][0] + (v.second << 1));
}
siz += p;
}
return siz;
}
Compilation message
museum.cpp: In function 'int main()':
museum.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d%d", &n, &k, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
museum.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d%d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
246348 KB |
Output is correct |
2 |
Correct |
47 ms |
250044 KB |
Output is correct |
3 |
Correct |
95 ms |
345684 KB |
Output is correct |
4 |
Correct |
60 ms |
281420 KB |
Output is correct |
5 |
Correct |
46 ms |
260332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
246348 KB |
Output is correct |
2 |
Correct |
47 ms |
250044 KB |
Output is correct |
3 |
Correct |
95 ms |
345684 KB |
Output is correct |
4 |
Correct |
60 ms |
281420 KB |
Output is correct |
5 |
Correct |
46 ms |
260332 KB |
Output is correct |
6 |
Correct |
43 ms |
246352 KB |
Output is correct |
7 |
Correct |
74 ms |
305380 KB |
Output is correct |
8 |
Correct |
12 ms |
4700 KB |
Output is correct |
9 |
Correct |
11 ms |
4700 KB |
Output is correct |
10 |
Correct |
13 ms |
21852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 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 |
604 KB |
Output is correct |
6 |
Correct |
42 ms |
246348 KB |
Output is correct |
7 |
Correct |
47 ms |
250044 KB |
Output is correct |
8 |
Correct |
95 ms |
345684 KB |
Output is correct |
9 |
Correct |
60 ms |
281420 KB |
Output is correct |
10 |
Correct |
46 ms |
260332 KB |
Output is correct |
11 |
Correct |
43 ms |
246352 KB |
Output is correct |
12 |
Correct |
74 ms |
305380 KB |
Output is correct |
13 |
Correct |
12 ms |
4700 KB |
Output is correct |
14 |
Correct |
11 ms |
4700 KB |
Output is correct |
15 |
Correct |
13 ms |
21852 KB |
Output is correct |
16 |
Correct |
59 ms |
246860 KB |
Output is correct |
17 |
Correct |
140 ms |
251992 KB |
Output is correct |
18 |
Correct |
90 ms |
288084 KB |
Output is correct |
19 |
Correct |
68 ms |
4652 KB |
Output is correct |
20 |
Correct |
35 ms |
37204 KB |
Output is correct |
21 |
Correct |
225 ms |
309836 KB |
Output is correct |
22 |
Correct |
143 ms |
256592 KB |
Output is correct |
23 |
Correct |
285 ms |
4700 KB |
Output is correct |
24 |
Correct |
123 ms |
35212 KB |
Output is correct |
25 |
Correct |
294 ms |
350484 KB |
Output is correct |