제출 #1252176

#제출 시각아이디문제언어결과실행 시간메모리
1252176rayan_bdMuseum (CEOI17_museum)C++20
0 / 100
2 ms836 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 10005; const int MAXK = 10005; #define int long long const int INF = 5e18; 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 = 0; 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() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k >> x; 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; }

컴파일 시 표준 에러 (stderr) 메시지

museum.cpp: In function 'int main()':
museum.cpp:47:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...