# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095003 | 2024-10-01T07:07:43 Z | blackslex | Museum (CEOI17_museum) | C++17 | 365 ms | 1048576 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = 1e4 + 5; int n, k, c, x, y, z, sz[N]; ll dp[N][2][N]; vector<pii> v[N]; void dfs (int cur, int par) { sz[cur] = 1; 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]; } } int main() { scanf("%d %d %d", &n, &k, &c); 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); } for (int i = 1; i <= n; i++) { for (auto j: {0, 1}) { for (int k = 2; k <= n; k++) dp[i][j][k] = 1e18; } } dfs(c, 0); printf("%lld", min(dp[c][0][k], dp[c][1][k])); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 0 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 0 ms | 604 KB | Output is correct |
5 | Correct | 0 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 365 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 365 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 0 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 604 KB | Output is correct |
4 | Correct | 0 ms | 604 KB | Output is correct |
5 | Correct | 0 ms | 860 KB | Output is correct |
6 | Runtime error | 365 ms | 1048576 KB | Execution killed with signal 9 |
7 | Halted | 0 ms | 0 KB | - |