# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236404 | 2020-06-02T03:45:08 Z | mahmoudbadawy | Biochips (IZhO12_biochips) | C++17 | 695 ms | 402296 KB |
#include <bits/stdc++.h> using namespace std; const int N=2e5+5; vector<int> adj[N]; int arr[N],dp[N][505]; int n,m; void dfs(int node) { int tmp[505]; for(int u:adj[node]) { dfs(u); for(int i=0;i<=m;i++) tmp[i]=0; for(int i=0;i<=m;i++) { if(i&&dp[node][i]==0) break; for(int j=1;i+j<=m;j++) { if(dp[u][j]==0) break; tmp[i+j]=max(tmp[i+j],dp[node][i]+dp[u][j]); } } for(int i=0;i<=m;i++) dp[node][i]=max(dp[node][i],tmp[i]); } dp[node][1]=max(dp[node][1],arr[node]); } int main() { scanf("%d %d",&n,&m); int root=-1; for(int i=1;i<=n;i++) { int pa; scanf("%d %d",&pa,&arr[i]); if(pa) adj[pa].push_back(i); else root=i; } dfs(root); cout << dp[root][m] << endl; /*for(int x=1;x<=n;x++) { for(int i=0;i<=m;i++) cout << dp[x][i] << " "; cout << endl; }*/ return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 4992 KB | Output is correct |
2 | Correct | 7 ms | 4992 KB | Output is correct |
3 | Correct | 8 ms | 5248 KB | Output is correct |
4 | Correct | 23 ms | 22784 KB | Output is correct |
5 | Correct | 26 ms | 24960 KB | Output is correct |
6 | Correct | 26 ms | 24832 KB | Output is correct |
7 | Correct | 387 ms | 298232 KB | Output is correct |
8 | Correct | 392 ms | 298232 KB | Output is correct |
9 | Correct | 577 ms | 364808 KB | Output is correct |
10 | Correct | 695 ms | 402296 KB | Output is correct |