제출 #292022

#제출 시각아이디문제언어결과실행 시간메모리
292022shivensinha4Museum (CEOI17_museum)C++17
20 / 100
3101 ms84600 KiB
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const int MXN = 1e4+1; int n, k; vector<vector<pair<int, int>>> adj; int dp[MXN+1][2][MXN+1]; int sub[MXN+1]; const int INF = 1e8; void dfs(int p, int parent) { sub[p] = 1; dp[p][0][1] = dp[p][1][1] = 0; for (auto i: adj[p]) if (i.first != parent) { dfs(i.first, p); for_(j, 1, sub[i.first]+1) dp[p][0][sub[p]+j] = dp[p][1][sub[p]+j] = INF; sub[p] += sub[i.first]; for (int ct = sub[p]; ct >= 2; ct--) for (int t = min(ct-1, sub[i.first]); t >= 1; t--) { dp[p][1][ct] = min(dp[p][1][ct], dp[p][1][ct-t] + dp[i.first][1][t] + 2*i.second); dp[p][0][ct] = min(dp[p][0][ct], dp[p][0][ct-t] + dp[i.first][1][t] + 2*i.second); dp[p][0][ct] = min(dp[p][0][ct], dp[p][1][ct-t] + dp[i.first][0][t] + i.second); } } } int main() { #ifndef ONLINE_JUDGE //freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int x; cin >> n >> k >> x; adj.resize(n); for_(i, 0, n-1) { int a, b, w; cin >> a >> b >> w; a -= 1; b -= 1; adj[a].push_back({b, w}); adj[b].push_back({a, w}); } x -= 1; dfs(x, x); cout << dp[x][0][k] << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...