Submission #857230

# Submission time Handle Problem Language Result Execution time Memory
857230 2023-10-05T15:33:58 Z aykhn Biochips (IZhO12_biochips) C++14
50 / 100
2000 ms 403564 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
typedef long long ll;
 
#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
 
const int MXN = 2e5 + 5;
const int MXM = 5e2 + 5;
 
int n, m, r;
vector<int> adj[MXN];
int p[MXN], c[MXN];
int dp[MXN][MXM];
 
void dfs(int a)
{
    for (int v : adj[a]) dfs(v);
    int n1 = (int)adj[a].size();
    vector<vector<int>> dp1(n1 + 5, vector<int> (MXM, 0));
    for (int i = 1; i <= n1; i++)
    {
        int v = adj[a][i - 1];
        for (int j = 0; j <= m; j++)
        {
            for (int k = 0; k <= j; k++)
            {
                dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - k] + dp[v][k]);
            }
        }
    }
    dp[a][1] = max(c[a], dp1[n1][1]);
    for (int i = 2; i <= m; i++) dp[a][i] = dp1[n1][i];
}
 
signed main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i] >> c[i];
        if (!p[i])
        {
            r = i;
            continue;
        }
        adj[p[i]].pb(i);
    }
    dfs(r);
    cout << dp[r][m] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8024 KB Output is correct
2 Incorrect 2 ms 7768 KB Output isn't correct
3 Correct 2 ms 10072 KB Output is correct
4 Correct 27 ms 26460 KB Output is correct
5 Correct 45 ms 28648 KB Output is correct
6 Correct 66 ms 28652 KB Output is correct
7 Execution timed out 2029 ms 301476 KB Time limit exceeded
8 Execution timed out 2077 ms 301048 KB Time limit exceeded
9 Execution timed out 2051 ms 366452 KB Time limit exceeded
10 Execution timed out 2056 ms 403564 KB Time limit exceeded