# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1096296 | 2024-10-04T08:49:55 Z | vjudge1 | Museum (CEOI17_museum) | C++17 | 412 ms | 1048576 KB |
#include <iostream> #include <vector> #include <bits/stdc++.h> using namespace std; #define minimize(a,b) a=min(a,b) const int INF = 1e9+7; const int MAXN = 1e4+3; int n, k, root; struct Edge { int u, v, w; Edge(){} Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w) {} int other(const int x){return x^u^v;} } edge[MAXN]; vector<int> e[MAXN]; int sz[MAXN]; int64_t dp[MAXN][2][MAXN]; void dfs(int u=root, int p=0){ dp[u][0][1] = dp[u][1][1] = 0; sz[u] = 1; for(int &z : e[u]){ int v = edge[z].other(u), w = edge[z].w; if(p==v)continue; dfs(v, u); for(int szu = sz[u]; szu>=0; --szu) for(int szv = sz[v]; szv>=0; --szv){ minimize(dp[u][0][szu+szv], dp[u][0][szu] + dp[v][0][szv] + 2*w); minimize(dp[u][1][szu+szv], dp[u][0][szu] + dp[v][1][szv] + w); minimize(dp[u][1][szu+szv], dp[u][1][szu] + dp[v][0][szv] + 2*w); } sz[u]+=sz[v]; } } signed main() { cin.tie(0) -> sync_with_stdio(0); if(fopen("*.inp", "r")){ freopen("*.inp", "r",stdin); freopen("*.out", "w",stdout); } cin >> n >> k >> root; for(int u, v, i=1; i<n; ++i){ cin >> edge[i].u >> edge[i].v >> edge[i].w; e[edge[i].u].emplace_back(i); e[edge[i].v].emplace_back(i); } for (int i = 1; i <= n; ++i) for (int j = 2; j <= n; ++j) dp[i][0][j] = dp[i][1][j] = INF; dfs(); cout << min(dp[root][0][k], dp[root][1][k]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 856 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 412 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 412 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 856 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Runtime error | 412 ms | 1048576 KB | Execution killed with signal 9 |
7 | Halted | 0 ms | 0 KB | - |