Submission #1252165

#TimeUsernameProblemLanguageResultExecution timeMemory
1252165rayan_bdMuseum (CEOI17_museum)C++20
0 / 100
0 ms576 KiB
#include <bits/stdc++.h> using namespace std; const int INF = 1e18; const int MAXN = 505; const int MAXK = 505; #define int long long vector<pair<int, int>> adj[MAXN]; int dp[MAXN][MAXK][2]; int n, k, x; void dfs(int u, int par) { dp[u][1][0] = 0; dp[u][1][1] = 0; for (auto [v, cost] : adj[u]) { if (v == par) continue; dfs(v, u); int tmp[MAXK][2]; for (int i = 0; i <= k; ++i) tmp[i][0] = tmp[i][1] = INF; for (int i = 1; i <= k; ++i) { if (dp[u][i][0] == INF && dp[u][i][1] == INF) continue; for (int j = 1; j <= k - i; ++j) { if (dp[v][j][0] == INF && dp[v][j][1] == INF) continue; tmp[i + j][0] = min(tmp[i + j][0], dp[u][i][0] + dp[v][j][0] + 2 * cost); tmp[i + j][1] = min(tmp[i + j][1], dp[u][i][0] + dp[v][j][1] + cost); tmp[i + j][1] = min(tmp[i + j][1], dp[u][i][1] + dp[v][j][0] + 2 * cost); } } for (int i = 2; i <= k; ++i) { dp[u][i][0] = min(dp[u][i][0], tmp[i][0]); dp[u][i][1] = min(dp[u][i][1], tmp[i][1]); } } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> x >> k; for (int i = 1; i < n; ++i) { int a, b, c; cin >> a >> b >> c; adj[a].emplace_back(b, c); adj[b].emplace_back(a, c); } for (int i = 1; i <= n; ++i) for (int j = 0; j <= k; ++j) dp[i][j][0] = dp[i][j][1] = INF; dfs(x, -1); int answer = min(dp[x][k][0], dp[x][k][1]); cout << answer << '\n'; return 0; }

Compilation message (stderr)

museum.cpp:4:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
    4 | const int INF = 1e18;
      |                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...