Submission #598443

# Submission time Handle Problem Language Result Execution time Memory
598443 2022-07-18T11:22:42 Z AlesL0 Magic Tree (CEOI19_magictree) C++17
0 / 100
2000 ms 11336 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

vector <ll> val, w, d, dp;

void dfs_getval(ll c, ll v, vector <ll> g[]){
    if (v != c && d[c] == d[v])val[v] += w[c];
    for (auto k : g[c])dfs_getval(k, v, g);
}

void dfs_dp(ll c, vector <ll> g[]){
    ll sum = 0;
    for (auto k : g[c]){
        dfs_dp(k, g);
        sum += dp[k];
    }
    dp[c] = max(val[c], sum);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, m, k; cin >> n >> m >> k;
    vector <ll> g[n+1];
    val.resize(n+1, 0); w.resize(n+1, 0); d.resize(n+1, -1); dp.resize(n+1);
    for (int i = 2; i <= n; i++){
        ll a; cin >> a;
        g[a].push_back(i);
    }
    while (m--){
        ll a, b, c; cin >> a >> b >> c;
        w[a] = c;
        val[a] = c;
        d[a] = b;
    }
    for (int i = 1; i <= n; i++)dfs_getval(i, i, g);
    dfs_dp(1, g);
    cout << dp[1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 8524 KB Output is correct
2 Execution timed out 2080 ms 11336 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Incorrect 4 ms 468 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 100 ms 9716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -