# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
952009 |
2024-03-23T03:39:06 Z |
vjudge1 |
Museum (CEOI17_museum) |
C++14 |
|
3000 ms |
756836 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, k, x;
int dp[N][N][2];
int son[N];
vector<pair<int, int>> G[N];
void dfs(int fa, int u){
son[u] = 1;
dp[u][0][0] = dp[u][1][0] = dp[u][1][1] = dp[u][0][1] = 0;
for(auto e : G[u]){
int v = e.first;
int w = e.second;
if(v == fa) continue;
dfs(u, v);
son[u] += son[v];
for(int i = min(son[u], k); i >= 0; i--){
for(int j = 0; j <= min(i, son[v]); j++){
dp[u][i][0] = min(dp[u][i - j][0] + dp[v][j][0] + 2 * w, dp[u][i][0]);
dp[u][i][1] = min(dp[u][i - j][1] + dp[v][j][0] + w * 2, dp[u][i][1]);
dp[u][i][1] = min(dp[u][i - j][0] + dp[v][j][1] + w, dp[u][i][1]);
}
}
}
}
int main(){
// freopen("museum.in","r", stdin);
// freopen("museum.out","w", stdout);
scanf("%d %d %d", &n, &k, &x);
for(int i = 1; i < n; i++){
int x, y ,z;
scanf("%d %d %d", &x, &y, &z);
G[x].push_back({y, z});
G[y].push_back({x, z});
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= k; j++){
dp[i][j][1] = dp[i][j][0] = 1e9;
}
}
dfs(0, x);
printf("%d", dp[x][k][1]);
}
Compilation message
museum.cpp: In function 'int main()':
museum.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d %d %d", &n, &k, &x);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | scanf("%d %d %d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
257884 KB |
Output is correct |
2 |
Correct |
48 ms |
259932 KB |
Output is correct |
3 |
Correct |
83 ms |
258136 KB |
Output is correct |
4 |
Correct |
70 ms |
263764 KB |
Output is correct |
5 |
Correct |
59 ms |
263508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
257884 KB |
Output is correct |
2 |
Correct |
48 ms |
259932 KB |
Output is correct |
3 |
Correct |
83 ms |
258136 KB |
Output is correct |
4 |
Correct |
70 ms |
263764 KB |
Output is correct |
5 |
Correct |
59 ms |
263508 KB |
Output is correct |
6 |
Correct |
45 ms |
263508 KB |
Output is correct |
7 |
Correct |
81 ms |
261968 KB |
Output is correct |
8 |
Correct |
48 ms |
261768 KB |
Output is correct |
9 |
Correct |
50 ms |
261952 KB |
Output is correct |
10 |
Correct |
47 ms |
263760 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 |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
48 ms |
257884 KB |
Output is correct |
7 |
Correct |
48 ms |
259932 KB |
Output is correct |
8 |
Correct |
83 ms |
258136 KB |
Output is correct |
9 |
Correct |
70 ms |
263764 KB |
Output is correct |
10 |
Correct |
59 ms |
263508 KB |
Output is correct |
11 |
Correct |
45 ms |
263508 KB |
Output is correct |
12 |
Correct |
81 ms |
261968 KB |
Output is correct |
13 |
Correct |
48 ms |
261768 KB |
Output is correct |
14 |
Correct |
50 ms |
261952 KB |
Output is correct |
15 |
Correct |
47 ms |
263760 KB |
Output is correct |
16 |
Correct |
128 ms |
311916 KB |
Output is correct |
17 |
Correct |
709 ms |
535384 KB |
Output is correct |
18 |
Correct |
1852 ms |
313940 KB |
Output is correct |
19 |
Correct |
117 ms |
311888 KB |
Output is correct |
20 |
Correct |
107 ms |
313672 KB |
Output is correct |
21 |
Execution timed out |
3052 ms |
756836 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |