253342026-02-19 11:15:30KevinRaktárba szállítás (45 pont)cpp17Wrong answer 9/459ms2524 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

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

    int N, K;
    ll C;
    cin >> N >> K >> C;

    vector<int> parent(N + 1);
    vector<ll> A(N + 1);

    for (int i = 1; i <= N; i++) {
        cin >> parent[i] >> A[i];
    }

    vector<vector<int>> children(N + 1);
    for (int i = 2; i <= N; i++) {
        children[parent[i]].push_back(i);
    }

    // Path sum számítás
    vector<ll> path_sum(N + 1, 0);

    function<void(int)> dfs = [&](int u) {
        for (int v : children[u]) {
            path_sum[v] = path_sum[u] + A[v];
            dfs(v);
        }
    };

    path_sum[1] = 0;
    dfs(1);

    // levelek gyűjtése
    priority_queue<ll> pq;

    for (int i = 2; i <= N; i++) {
        if (children[i].empty()) {
            pq.push(path_sum[i]);
        }
    }

    ll result = 0;

    for (int i = 0; i < K && !pq.empty(); i++) {
        ll val = pq.top();
        pq.pop();
        result += min(val, C);
    }

    cout << result << "\n";
}
SubtaskSumTestVerdictTimeMemory
base9/45
1Accepted0/01ms316 KiB
2Wrong answer0/04ms1076 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/12ms500 KiB
9Accepted1/14ms1060 KiB
10Accepted1/14ms1076 KiB
11Accepted1/14ms1076 KiB
12Wrong answer0/11ms316 KiB
13Wrong answer0/11ms316 KiB
14Wrong answer0/11ms316 KiB
15Wrong answer0/11ms316 KiB
16Wrong answer0/11ms316 KiB
17Wrong answer0/11ms560 KiB
18Wrong answer0/11ms540 KiB
19Wrong answer0/11ms316 KiB
20Wrong answer0/11ms316 KiB
21Wrong answer0/26ms1076 KiB
22Wrong answer0/26ms1076 KiB
23Wrong answer0/24ms1076 KiB
24Wrong answer0/38ms1636 KiB
25Wrong answer0/39ms1588 KiB
26Wrong answer0/34ms1332 KiB
27Wrong answer0/34ms1332 KiB
28Wrong answer0/38ms2464 KiB
29Wrong answer0/38ms2524 KiB
30Wrong answer0/37ms2360 KiB