Submission #867463

# Submission time Handle Problem Language Result Execution time Memory
867463 2023-10-28T12:40:48 Z sleepntsheep Biochips (IZhO12_biochips) C++17
30 / 100
56 ms 40536 KB
#include <iostream>
#include <cstring>
#include <cassert>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 200050
using ll = long long;

int n, m, a[N], timer, dp[2][N], in[N], dp2[501][N], sz[N], hi[N];
vector<int> g[N], g2[N];
vector<tuple<int, int, int>> v;

void dfs1(int u)
{
    ++sz[u];
    for (auto v : g[u])
    {
        dfs1(v);
        for (int i = sz[u]; i--;)
            for (int j = 0; j <= sz[v]; ++j)
                dp2[i+j][u] = max(dp2[i+j][u], dp2[i][u] + dp2[j][v]);
        sz[u] += sz[v];
    }
    dp2[1][u] = max(dp2[1][u], a[u]);
}

int main()
{
    ShinLena;
    cin >> n >> m;
    for (int p, i = 1; i <= n; ++i) cin >> p >> a[i], g[p].push_back(i);
    dfs1(0);
    cout << dp2[m][0];
    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Runtime error 35 ms 36444 KB Execution killed with signal 11
5 Runtime error 35 ms 35924 KB Execution killed with signal 11
6 Runtime error 40 ms 40536 KB Execution killed with signal 11
7 Runtime error 48 ms 34640 KB Execution killed with signal 11
8 Runtime error 50 ms 35264 KB Execution killed with signal 11
9 Runtime error 48 ms 32852 KB Execution killed with signal 11
10 Runtime error 56 ms 33364 KB Execution killed with signal 11