Submission #775737

# Submission time Handle Problem Language Result Execution time Memory
775737 2023-07-06T20:50:21 Z danikoynov Magic Tree (CEOI19_magictree) C++14
0 / 100
2000 ms 37824 KB
/**
 ____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|

**/

#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e5 + 10, maxk = 21;
int n, m, k, p[maxn], w[maxn], d[maxn];
ll dp[maxn][maxk], diff[maxn][maxk];
vector < int > adj[maxn];

void dfs(int v)
{
    for (int u : adj[v])
    {
        dfs(u);
        for (int j = 1; j <= k; j ++)
        {
            dp[v][j] += dp[u][j];
            diff[v][j - 1] += dp[u][j];
            diff[v][j] -= dp[u][j];
                for (int j = 2; j <= k; j ++)
        dp[v][j] = max(dp[v][j], dp[v][j - 1]);
            /**int pt = j;
            ll sum = diff[v][j];
            while(sum < 0)
            {

            }*/
        }
    }

    if (d[v] != 0)
        dp[v][d[v]] += w[v];
    for (int j = 2; j <= k; j ++)
        dp[v][j] = max(dp[v][j], dp[v][j - 1]);
}

void solve()
{
    cin >> n >> m >> k;
    for (int i = 2; i <= n; i ++)
    {
        cin >> p[i];
        adj[p[i]].push_back(i);
    }
    for (int i = 1; i <= m; i ++)
    {
        int v;
        cin >> v >> d[v] >> w[v];
    }

    dfs(1);

    cout << dp[1][k] << endl;
}

int main()
{
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 6648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 999 ms 3104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 130 ms 37824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 4584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -