# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
13259 | dohyun0324 | Biochips (IZhO12_biochips) | C++98 | 421 ms | 407760 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |