| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 27195 | TAMREF | Biochips (IZhO12_biochips) | C++11 | 3 ms | 399676 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 <bits/stdc++.h>
using namespace std;
int dp[200001][501], par[200001], m[200001];
vector<int> C[200001];
int N,M,rt;
void dfs(int x){
    for(int u : C[x]) dfs(u);
    dp[x][1]=max(dp[x][1],m[x]);
    if(!par[x]) return;
    for(int f=M;f;f--){
        dp[par[x]][f]=max(dp[par[x]][f],dp[x][f]);
        for(int j=1;j<f;j++)
            if(dp[par[x]][j] && dp[x][f-j]) dp[par[x]][f]=max(dp[par[x]][f],dp[par[x]][j]+dp[x][f-j]);
    }
}
int main(){
    scanf("%d%d",&N,&M);
    for(int i=1;i<=N;i++){
        scanf("%d%d",&par[i],&m[i]);
        if(!par[i]) rt=i;
        else C[par[i]].push_back(i);
    }
    dfs(rt);
    printf("%d\n",dp[rt][M]);
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
