Submission #896400

# Submission time Handle Problem Language Result Execution time Memory
896400 2024-01-01T11:20:10 Z math_rabbit_1028 Magic Tree (CEOI19_magictree) C++14
3 / 100
47 ms 5444 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, m, k, par[101010];
pii arr[101010];

int cnt[101010];
priority_queue<pii> pq;
ll ans = 0;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> k;
    for (int i = 2; i <= n; i++) cin >> par[i];
    for (int i = 1; i <= m; i++) {
        int v, d, w;
        cin >> v >> d >> w;
        arr[v] = {d, w};
    }
    for (int i = 2; i <= n; i++) cnt[par[i]]++;

    for (int i = 1; i <= n; i++) {
        if (cnt[i] == 0) pq.push({-arr[i].first, i});
    }

    int now = 1;
    while (!pq.empty()) {
        while (!pq.empty() && now >= -pq.top().first) {
            int v = pq.top().second;
            if (now == -pq.top().first) ans += arr[v].second;
            pq.pop();
            cnt[par[v]]--;
            if (par[v] > 1 && cnt[par[v]] == 0) pq.push({arr[par[v]].first, par[v]});
        }
        now++;
    }

    cout << ans << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3552 KB Output is correct
2 Correct 16 ms 2652 KB Output is correct
3 Correct 47 ms 5444 KB Output is correct
4 Correct 35 ms 4828 KB Output is correct
5 Correct 39 ms 5032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 4804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -