151222025-02-13 10:10:04BencuTársaság (50)cpp17Wrong answer 7/509ms820 KiB
/*#include <bits/stdc++.h>

using namespace std;
int n,k;
struct Bencu {
    int apa;
    int ido;
}a[10001];

int main()
{
    ifstream f("be.in");
    cin>>n>>k;
    for (int i=2; i<=n; i++) {
        cin>>a[i].apa>>a[i].ido;
    }
    cout<<0;
    return 0;
}*/
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

struct Node {
    int id, wait_time;
    vector<int> children;
};

int find_min_max_wait_time(int N, int K, vector<Node>& nodes) {
    vector<int> max_wait_time(N + 1, 0);

    // BFS a maximális várakozási idő meghatározásához
    queue<int> q;
    q.push(1); // A vezető (1-es csúcs) az első
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (int child : nodes[node].children) {
            max_wait_time[child] = max_wait_time[node] + nodes[child].wait_time;
            q.push(child);
        }
    }

    // A legrosszabb várakozási idő csökkentése K ember kijelölésével
    vector<int> wait_times;
    for (int i = 2; i <= N; i++) {
        wait_times.push_back(max_wait_time[i]);
    }

    sort(wait_times.rbegin(), wait_times.rend()); // Csökkenő sorrendbe rendezzük
    return wait_times.size() > K ? wait_times[K] : 0;
}

int main() {
    int N, K;
    cin >> N >> K;

    vector<Node> nodes(N + 1);
    for (int i = 1; i <= N; i++) {
        nodes[i].id = i;
    }

    for (int i = 2; i <= N; i++) {
        int boss, time;
        cin >> boss >> time;
        nodes[boss].children.push_back(i);
        nodes[i].wait_time = time;
    }

    cout << find_min_max_wait_time(N, K, nodes) << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/06ms748 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms508 KiB
5Accepted3/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Wrong answer0/32ms500 KiB
9Wrong answer0/32ms316 KiB
10Wrong answer0/33ms532 KiB
11Wrong answer0/34ms564 KiB
12Wrong answer0/34ms564 KiB
13Wrong answer0/46ms736 KiB
14Wrong answer0/47ms820 KiB
15Wrong answer0/48ms716 KiB
16Accepted4/48ms820 KiB
17Wrong answer0/49ms816 KiB