제출 #1252180

#제출 시각아이디문제언어결과실행 시간메모리
1252180rayan_bdMuseum (CEOI17_museum)C++20
0 / 100
526 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 10005; #define int long long const int INF = 5e18; vector<pair<int, int>> adj[MAXN]; int dp[MAXN][MAXN][2], sz[MAXN]; int n, k, x; void dfs(int u, int par) { dp[u][1][0] = dp[u][1][1] = 0; sz[u] = 1; for (auto [v, cost] : adj[u]) { if (v == par) continue; dfs(v, u); for(int i = sz[u]; i >= 0; --i){ for(int j = sz[v]; j >= 0; --j){ dp[u][i + j][0] = min(dp[u][i + j][0], dp[u][i][0] + dp[v][j][0] + cost * 2); dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][1] + dp[v][j][0] + cost * 2); dp[u][i + j][1] = min(dp[u][i + j][1], dp[u][i][0] + dp[v][j][1] + cost); } } sz[u] += sz[v]; } } 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); } memset(dp, 0x3f, sizeof(dp)); dfs(x, -1); int answer = min(dp[x][k][0], dp[x][k][1]); cout << dp[x][k][1] << '\n'; return 0; }

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

museum.cpp: In function 'int main()':
museum.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
museum.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         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...