# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302572 | 2020-09-18T19:36:40 Z | milisav | Biochips (IZhO12_biochips) | C++14 | 379 ms | 407928 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") #define maxn 200010 #define maxm 510 using namespace std; int n,m; vector<int> rt; int p[maxn]; int x[maxn]; vector<int> ch[maxn]; int a[maxn]; int s[maxn]; int dp[maxn][maxm]; int id=0; int tot=0; void dfs(int u) { int cid=id++; a[cid]=x[u]; tot++; for(int i=0;i<ch[u].size();i++) { dfs(ch[u][i]); } s[cid]=id; } int main() { scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d %d",&p[i],&x[i]); if(p[i]==0) rt.push_back(i); else ch[p[i]].push_back(i); } for(auto u:rt) dfs(u); assert(tot==n); for(int j=1;j<=m;j++) dp[0][j]=-1e9; for(int i=0;i<n;i++) { for(int j=0;j<=m;j++) dp[i+1][j]=max(dp[i+1][j],dp[i][j]); for(int j=0;j<=m-1;j++) dp[s[i]][j+1]=max(dp[s[i]][j+1],dp[i][j]+a[i]); } printf("%d",dp[n][m]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 5120 KB | Output is correct |
2 | Correct | 3 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 5248 KB | Output is correct |
4 | Correct | 20 ms | 23168 KB | Output is correct |
5 | Correct | 22 ms | 25344 KB | Output is correct |
6 | Correct | 22 ms | 25344 KB | Output is correct |
7 | Correct | 277 ms | 304608 KB | Output is correct |
8 | Correct | 284 ms | 304504 KB | Output is correct |
9 | Correct | 340 ms | 369656 KB | Output is correct |
10 | Correct | 379 ms | 407928 KB | Output is correct |