# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388014 | b00n0rp | 바이오칩 (IZhO12_biochips) | C++17 | 295 ms | 399256 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.
/*
not my code. checking to submit whether the site is even working
*/
#include<bits/stdc++.h>
using namespace std;
int val[200001], m, t;
vector<int> g[200001];
int dp[200001][501], par[200001];
void dfs(int c)
{
par[c] = t;
for(int e : g[c]) dfs(e);
for(int i=1;i<=m;i++)
dp[t+1][i] = max(dp[t][i],dp[par[c]][i-1]+val[c]);
t++;
}
int main()
{
int n, r;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
int p;
scanf("%d%d",&p,val+i);
if(!p) r = i;
else g[p].push_back(i);
}
for(int i=1;i<=m;i++) dp[0][i] = -1e9;
dfs(r);
printf("%d\n",dp[n][m]);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |