Submission #881184

# Submission time Handle Problem Language Result Execution time Memory
881184 2023-11-30T19:45:11 Z alexdd Biochips (IZhO12_biochips) C++17
100 / 100
593 ms 402312 KB
#include<iostream>
#include<vector>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
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[nod]);j<=min(siz[adj],i);j++)
                dp[nod][i] = max(dp[nod][i], dp[nod][i-j] + dp[adj][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
1 Correct 2 ms 7772 KB Output is correct
2 Correct 2 ms 7772 KB Output is correct
3 Correct 2 ms 8028 KB Output is correct
4 Correct 11 ms 25436 KB Output is correct
5 Correct 12 ms 27756 KB Output is correct
6 Correct 13 ms 27740 KB Output is correct
7 Correct 271 ms 300260 KB Output is correct
8 Correct 289 ms 300356 KB Output is correct
9 Correct 468 ms 364628 KB Output is correct
10 Correct 593 ms 402312 KB Output is correct