Submission #435929

#TimeUsernameProblemLanguageResultExecution timeMemory
435929cgiosyBiochips (IZhO12_biochips)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; void mx(int&a, int b) { a=max(a, b); } int main() { ios::sync_with_stdio(0);cin.tie(0); int N, K, r; cin>>N>>K; int D[N+1][500], F[N+1], G[N+1]{}, W[N+1]; for(int i=1; i<=N; i++) { int p; cin>>p>>W[i]; if(p) F[i]=G[p], G[p]=i; else r=i; } function<int(int)> dfs=[&](int i) { int n=0; for(int e=G[i]; e; e=F[e]) { int m=dfs(e), j=min(n+m, K); while(n<j) D[i][n++]=-1e9; while(--j) for(int k=min(m, j); k--;) mx(D[i][j], D[i][j-k-1]+D[e][k]); for(int k=0; k<m; k++) mx(D[i][k], D[e][k]); } if(n) mx(D[i][0], W[i]); else D[i][n++]=W[i]; return n; }; cout<<D[r][dfs(r)-1]<<'\n'; }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:29:24: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |  cout<<D[r][dfs(r)-1]<<'\n';
      |                        ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...