Submission #27195

#TimeUsernameProblemLanguageResultExecution timeMemory
27195TAMREFBiochips (IZhO12_biochips)C++11
0 / 100
3 ms399676 KiB
#include <bits/stdc++.h> using namespace std; int dp[200001][501], par[200001], m[200001]; vector<int> C[200001]; int N,M,rt; void dfs(int x){ for(int u : C[x]) dfs(u); dp[x][1]=max(dp[x][1],m[x]); if(!par[x]) return; for(int f=M;f;f--){ dp[par[x]][f]=max(dp[par[x]][f],dp[x][f]); for(int j=1;j<f;j++) if(dp[par[x]][j] && dp[x][f-j]) dp[par[x]][f]=max(dp[par[x]][f],dp[par[x]][j]+dp[x][f-j]); } } int main(){ scanf("%d%d",&N,&M); for(int i=1;i<=N;i++){ scanf("%d%d",&par[i],&m[i]); if(!par[i]) rt=i; else C[par[i]].push_back(i); } dfs(rt); printf("%d\n",dp[rt][M]); }

Compilation message (stderr)

biochips.cpp: In function 'int main()':
biochips.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
                        ^
biochips.cpp:19:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&par[i],&m[i]);
                                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...