| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1370315 | sarahspeedy | Museum (CEOI17_museum) | C++20 | 57 ms | 17944 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const long long INF = 1e18;
const int N = 10005;
const int K = 105;
vector<pair<int,int>> adj[N];
long long dp[N][K][2];
int sz[N];
int n, k, x;
void dfs(int node, int parent){
sz[node] = 1;
for(int i = 0; i <= k; i++){
dp[node][i][0] = INF;
dp[node][i][1] = INF;
}
dp[node][1][0] = 0;
dp[node][1][1] = 0;
for(auto [child, w] : adj[node]){
if(child == parent) continue;
dfs(child, node);
static long long ndp[K][2];
for(int i = 0; i <= k; i++){
ndp[i][0] = INF;
ndp[i][1] = INF;
}
for(int a = 1; a <= sz[node]; a++){
for(int b = 1; b <= sz[child]; b++){
ndp[a+b][0] =
min(
ndp[a+b][0],
dp[node][a][0]
+
dp[child][b][0]
+
2LL * w
);
ndp[a+b][1] =
min(
ndp[a+b][1],
dp[node][a][1]
+
dp[child][b][0]
+
2LL * w
);
ndp[a+b][1] =
min(
ndp[a+b][1],
dp[node][a][0]
+
dp[child][b][1]
+
w
);
}
}
for(int i = 1; i <= sz[node] + sz[child]; i++){
dp[node][i][0] =
min(dp[node][i][0], ndp[i][0]);
dp[node][i][1] =
min(dp[node][i][1], ndp[i][1]);
}
sz[node] += sz[child];
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k >> x;
for(int i = 1; i < n; i++){
int u, v, w;
cin >> u >> v >> w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
dfs(x, 0);
cout << min(dp[x][k][0], dp[x][k][1]) << '\n';
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
