73952024-01-08 13:39:08tamasmarkTársaság (50)cpp17Wrong answer 0/5017ms18592 KiB
// tarsasag.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

using namespace std;

struct adat
{
    int lat;
    int keses,delay;
    deque<pair < int, int >> sz;
};
deque<adat>x;
priority_queue<int>p;
void melysegi(int csp)
{
    x[csp].lat = 1;
    for (auto& e : x[csp].sz)
    {
        if (!x[e.first].lat)
        {
            if (x[e.first].sz.size()>1)melysegi(e.first);
            else
            {
                x[e.first].keses = e.second;
                p.push(e.second);
            }
            if (csp != 1)
            {
                x[csp].keses = max(x[csp].keses,x[e.first].keses+x[csp].delay);
                
            }
        }
    }
    if(csp!=1)p.push(x[csp].keses);
}

int main()
{
    int n, k;
    cin >> n >> k;
    x.resize(n + 1);
    for (int i = 1; i <= n - 1; ++i)
    {
        int a, b;
        cin >> a >> b;
        x[i + 1].sz.push_back({ a,b });
        x[i + 1].delay = b;
        x[a].sz.push_back({ i + 1,b });
    }
    melysegi(1);
    for (int i = 1; i <= k; ++i)
    {
        p.pop();
    }
    cout << p.top();
    return 0;
}
/*
5 1
1 5
1 2
2 4
2 2
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/03ms1964 KiB
2Wrong answer0/010ms9208 KiB
3Wrong answer0/33ms2444 KiB
4Wrong answer0/33ms2812 KiB
5Wrong answer0/33ms3036 KiB
6Wrong answer0/33ms3400 KiB
7Wrong answer0/33ms3904 KiB
8Wrong answer0/34ms4864 KiB
9Wrong answer0/36ms6436 KiB
10Wrong answer0/37ms7932 KiB
11Wrong answer0/38ms9356 KiB
12Wrong answer0/39ms10884 KiB
13Wrong answer0/412ms12548 KiB
14Wrong answer0/413ms14052 KiB
15Wrong answer0/414ms15660 KiB
16Wrong answer0/417ms17120 KiB
17Wrong answer0/417ms18592 KiB