# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
27195 | 2017-07-10T11:42:14 Z | TAMREF | Biochips (IZhO12_biochips) | C++11 | 3 ms | 399676 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 399676 KB | Output is correct |
2 | Incorrect | 0 ms | 399676 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |