Submission #572543

# Submission time Handle Problem Language Result Execution time Memory
572543 2022-06-04T16:40:35 Z piOOE Magic Tree (CEOI19_magictree) C++17
13 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 100000;

map<int, ll> dp[N];

int p[N], d[N], w[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i < n; ++i) {
        cin >> p[i];
        --p[i];
    }
    for (int i = 0; i < m; ++i) {
        int v;
        cin >> v;
        --v;
        cin >> d[v] >> w[v];
    }
    for (int i = n - 1; i > -1; --i) {
        if (d[i] != 0) {
            if (dp[i].count(d[i]) && dp[i][d[i]] > w[i]) {
                continue;
            }
            ll sum = w[i] - dp[i][d[i]];
            dp[i][d[i]] = w[i];
            while (true) {
                auto it = dp[i].upper_bound(d[i]);
                if (it == dp[i].end()) {
                    break;
                }
                if (it->second <= sum) {
                    sum -= it->second;
                    dp[i].erase(it);
                } else {
                    it->second -= sum;
                    break;
                }
            }
        }
        if (i > 0) {
            for (auto [a, b] : dp[i]) {
                dp[p[i]][a] += b;
            }
        }
    }
    ll ans = 0;
    for (auto [a, b] : dp[0]) {
        ans += b;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 4 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 25408 KB Output is correct
2 Execution timed out 2115 ms 1048576 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 15888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 4 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5808 KB Output is correct
2 Correct 13 ms 7252 KB Output is correct
3 Correct 14 ms 7352 KB Output is correct
4 Correct 15 ms 7508 KB Output is correct
5 Correct 8 ms 6564 KB Output is correct
6 Correct 576 ms 265992 KB Output is correct
7 Correct 648 ms 292148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 4 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Incorrect 4 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -