Submission #13259

#TimeUsernameProblemLanguageResultExecution timeMemory
13259dohyun0324Biochips (IZhO12_biochips)C++98
100 / 100
421 ms407760 KiB
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; vector<int>con[200010]; int p,pos[200010],arr[200010],n,m,a[200010],d[200010][510],w=1; void dfs(int x) { int i,j; arr[x]=w; for(i=0;i<con[x].size();i++) dfs(con[x][i]); w++; pos[w]=x; for(i=1;i<=m;i++) d[w][i]=max(d[w][i],d[w-1][i]); for(i=1;i<=m;i++) d[w][i]=max(d[w][i],d[arr[x]][i-1]+a[x]); } int main() { int i,j,x,y; scanf("%d %d",&n,&m); for(i=0;i<=n;i++){ for(j=1;j<=m;j++){ d[i][j]=-2147483647; } } for(i=1;i<=n;i++) { scanf("%d %d",&x,&y); if(x==0) p=i; con[x].push_back(i); a[i]=y; } dfs(p); printf("%d",d[w][m]); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...