# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
881182 | alexdd | Biochips (IZhO12_biochips) | C++17 | 549 ms | 402512 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<iostream>
#include<vector>
using namespace std;
const int INF = 1e9;
int n,m,root;
vector<int> con[200005];
int a[200005];
int siz[200005];
int dp[200005][505];
void dfs(int nod)
{
for(auto adj:con[nod])
{
dfs(adj);
for(int i=min(m,siz[nod]+siz[adj]);i>0;i--)
{
for(int j=max(0,i-siz[adj]);j<=min(siz[nod],i);j++)
dp[nod][i] = max(dp[nod][i], dp[nod][j] + dp[adj][i-j]);
}
siz[nod]=min(siz[nod]+siz[adj],m);
}
dp[nod][1] = max(dp[nod][1], a[nod]);
siz[nod] = max(siz[nod], 1);
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
int p;
for(int i=1;i<=n;i++)
{
cin>>p>>a[i];
if(p!=0) con[p].push_back(i);
else root = i;
}
dfs(root);
cout<<dp[root][m];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |