답안 #572544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572544 2022-06-04T16:43:00 Z piOOE Magic Tree (CEOI19_magictree) C++17
16 / 100
140 ms 39860 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) {
            if (dp[p[i]].size() < dp[i].size())
                swap(dp[i], dp[p[i]]);
            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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 3 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 16844 KB Output is correct
2 Correct 26 ms 9700 KB Output is correct
3 Correct 140 ms 39860 KB Output is correct
4 Correct 72 ms 17628 KB Output is correct
5 Correct 120 ms 22856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 10384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 3 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5460 KB Output is correct
2 Correct 12 ms 6324 KB Output is correct
3 Correct 11 ms 6392 KB Output is correct
4 Correct 16 ms 6356 KB Output is correct
5 Correct 8 ms 6228 KB Output is correct
6 Correct 12 ms 6240 KB Output is correct
7 Correct 15 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 3 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Incorrect 3 ms 5028 KB Output isn't correct
3 Halted 0 ms 0 KB -