제출 #1255907

#제출 시각아이디문제언어결과실행 시간메모리
1255907_dtq_바이오칩 (IZhO12_biochips)C++20
60 / 100
493 ms589824 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define sz(x) (ll)(x.size()) #define all(v) v.begin(), v.end() #define se second #define fi first using namespace std; const ll N = 2e5 + 9; ll n, m, i, j, dp[N][509], root_, a[N], cnt, in[N], out[N]; vector<ll>vec[N], euler; void dfs( ll x, ll root ) { cnt ++; euler.pb(x); in[x] = cnt; for(auto k : vec[x]) if(k != root) dfs(k, x); out[x] = cnt; } int main() { #define TN "d" if(fopen(TN ".in", "r")) { freopen(TN ".in", "r", stdin); freopen(TN ".out", "w", stdout); } cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for( i = 1; i <= n; i ++ ) { ll u, v; cin >> u >> v; a[i] = v; if( u == 0 ) root_ = i; else vec[u].pb(i); } euler.pb(0); dfs(root_, 0); for( int w = 0; w <= cnt + 1; w ++ ) for( int j = 1; j <= m; j ++ ) dp[i][j] = -1e18; for( int w = sz(euler) - 1; w > 0; w -- ) { ll x = euler[w]; for( int j = 1; j <= m; j ++ ) { dp[w][j] = max(dp[w][j], dp[w + 1][j]); dp[w][j] = max(dp[w][j], dp[out[x] + 1][j - 1] + a[x]); } } cout << dp[1][m]; return 0; } /* */

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

biochips.cpp: In function 'int main()':
biochips.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(TN ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
biochips.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(TN ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...