제출 #337138

#제출 시각아이디문제언어결과실행 시간메모리
337138nvmdava바이오칩 (IZhO12_biochips)C++17
100 / 100
363 ms403308 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define ss second mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 200'005; const ll MOD = 1'000'000'007; const int INF = 0x3f3f3f3f; int dp[N][505]; vector<int> ch[N]; int cnt = 1, w[N], ww[N], l[N]; void dfs(int v){ int t = cnt; for(auto& x : ch[v]) dfs(x); ww[cnt] = w[v]; l[cnt++] = t; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; int root; for(int p, i = 1; i <= n; ++i){ cin>>p>>w[i]; if(p) ch[p].push_back(i); else root = i; } dfs(root); for(int i = 0; i <= n; ++i) for(int j = 1; j <= m; ++j) dp[i][j] = -0x3f3f3f3f; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) dp[i][j] = max(dp[i - 1][j], dp[l[i] - 1][j - 1] + ww[i]); cout<<dp[n][m]; }

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

biochips.cpp: In function 'int main()':
biochips.cpp:42:8: warning: 'root' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     dfs(root);
      |     ~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...