7395 2024. 01. 08 13:39:08 tamasmark Társaság (50) cpp17 Hibás válasz 0/50 17ms 18592 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
Részfeladat Összpont Teszt Verdikt Idő Memória
base 0/50
1 Elfogadva 0/0 3ms 1964 KiB
2 Hibás válasz 0/0 10ms 9208 KiB
3 Hibás válasz 0/3 3ms 2444 KiB
4 Hibás válasz 0/3 3ms 2812 KiB
5 Hibás válasz 0/3 3ms 3036 KiB
6 Hibás válasz 0/3 3ms 3400 KiB
7 Hibás válasz 0/3 3ms 3904 KiB
8 Hibás válasz 0/3 4ms 4864 KiB
9 Hibás válasz 0/3 6ms 6436 KiB
10 Hibás válasz 0/3 7ms 7932 KiB
11 Hibás válasz 0/3 8ms 9356 KiB
12 Hibás válasz 0/3 9ms 10884 KiB
13 Hibás válasz 0/4 12ms 12548 KiB
14 Hibás válasz 0/4 13ms 14052 KiB
15 Hibás válasz 0/4 14ms 15660 KiB
16 Hibás válasz 0/4 17ms 17120 KiB
17 Hibás válasz 0/4 17ms 18592 KiB