# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
716926 |
2023-03-31T12:04:37 Z |
Dan4Life |
Museum (CEOI17_museum) |
C++17 |
|
498 ms |
9708 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mxN=(int)1e4+10;
const int mxK=(int)1e2+10;
const int LINF = (int)1e9;
int n, k, s;
vector<pair<int,int>> adj[mxN];
int dp[mxN][mxK][2],dp2[mxN][mxK][2];
void dfs(int s, int p){
vector<pair<int,int>> v; v.clear();
for(auto [u,w] : adj[s]){
if(u==p) continue;
dfs(u,s); v.pb({u,w});
}
dp[s][1][0]=dp[s][1][1]=0;
if(!sz(v)) return;
for(int i = 0; i <= sz(v); i++)
for(int j = 0; j <= k; j++)
dp2[i][j][0]=dp2[i][j][1]=LINF;
dp2[0][0][0] = dp2[0][0][1] = 0;
for(int i = 1; i <= sz(v); i++){
for(int j = 0; j <= k; j++){
for(int x = 0; x < 2; x++){
dp2[i][j][x] = dp2[i-1][j][x];
for(int l = 1; l <= j; l++){
dp2[i][j][x] = min(dp2[i][j][x], dp2[i-1][j-l][x]+
dp[v[i-1].fi][l][x]+2*v[i-1].se);
if(x) continue;
dp2[i][j][0] = min(dp2[i][j][0], dp2[i-1][j-l][1]+
dp[v[i-1].fi][l][x]+v[i-1].se);
}
}
}
}
for(int i = 2; i <= k; i++)
for(int j = 0; j < 2; j++)
dp[s][i][j] = min(dp[s][i][j],dp2[sz(v)][i-1][j]);
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k >> s;
for(int i = 0; i < mxN; i++)
for(int j = 0; j < mxK; j++)
dp[i][j][0]=dp[i][j][1]=LINF;
for(int i = 1; i < n; i++){
int a, b, c; cin >> a >> b >> c;
adj[a].pb({b,c}), adj[b].pb({a,c});
}
dfs(s,-1); cout << dp[s][k][0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9172 KB |
Output is correct |
2 |
Correct |
6 ms |
9132 KB |
Output is correct |
3 |
Correct |
9 ms |
9152 KB |
Output is correct |
4 |
Incorrect |
6 ms |
9172 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
498 ms |
9708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
498 ms |
9708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9172 KB |
Output is correct |
2 |
Correct |
6 ms |
9132 KB |
Output is correct |
3 |
Correct |
9 ms |
9152 KB |
Output is correct |
4 |
Incorrect |
6 ms |
9172 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |