제출 #1126864

#제출 시각아이디문제언어결과실행 시간메모리
1126864ntdaccodeMuseum (CEOI17_museum)C++20
100 / 100
827 ms785232 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int N = 1e4 + 10; int n, k, root, f[2][N][N], g[2][N]; vector<ii> ke[N]; int sz[N]; void dfs(int u,int p = 0) { sz[u] = 1; for(int i = 0;i <= 1; i++) f[i][u][1] = f[i][u][0] = 0; for(ii tmp : ke[u]) { int v = tmp.first, w = tmp.second; if(v == p) continue; dfs(v,u); for(int i = 0;i <= sz[u] + sz[v]; i++) g[0][i] = g[1][i] = 1e9; for(int i = 1;i <= min(k,sz[u]); i++) { for(int j = 0;j <= min(k,sz[v]); j++) { if(i + j > k) break; g[0][i + j] = min(g[0][i + j], f[0][u][i] + f[0][v][j] + 2 * w); g[1][i + j] = min(g[1][i + j], f[0][u][i] + f[1][v][j] + w); g[1][i + j] = min(g[1][i + j], f[1][u][i] + f[0][v][j] + 2 * w); } } sz[u] += sz[v]; for(int i = 1;i <= sz[u]; i++){ for(int j = 0;j <= 1; j++) f[j][u][i] = min(g[j][i], f[j][u][i]); } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> k >> root; for(int i = 1;i <= n - 1; i++) { int u,v,w; cin >> u >> v >> w; ke[u].pb({v,w}); ke[v].pb({u,w}); } for(int i = 1;i <= n; i++) { for(int j = 0;j <= n; j++) { for(int e = 0;e <= 1; e++) f[e][i][j] = 1e9; } } dfs(root,0); cout << f[1][root][k]; }

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

museum.cpp: In function 'int32_t main()':
museum.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
museum.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
museum.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
museum.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     freopen(task".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...