7397 2024. 01. 08 13:51:04 tamasmark Társaság (50) cpp17 Hibás válasz 7/50 19ms 17868 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<int>p;
deque<adat>x;
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_back(e.second);
            }
            if (csp != 1)
            {
                x[csp].keses = max(x[csp].keses,x[e.first].keses+x[csp].delay);
                
            }
        }
    }
    if(csp!=1)p.push_back(x[csp].keses);
}
bool hasonlit(int a, int b)
{
    if(a>b) return 1;
    else return 0;
}

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);
    sort(p.begin(), p.end(),hasonlit);

    for (int i = 1; i <= k; ++i)
    {
        p.pop_front();
    }
    cout << p.front();
    return 0;
}
/*
5 1
1 5
1 2
2 4
2 2

9 2
1 6
1 4
2 3
2 4
3 2
3 5
5 2
5 1
*/
// 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 7/50
1 Elfogadva 0/0 3ms 1876 KiB
2 Hibás válasz 0/0 10ms 9188 KiB
3 Hibás válasz 0/3 3ms 2564 KiB
4 Hibás válasz 0/3 3ms 2720 KiB
5 Elfogadva 3/3 3ms 2848 KiB
6 Hibás válasz 0/3 3ms 3120 KiB
7 Hibás válasz 0/3 3ms 3536 KiB
8 Hibás válasz 0/3 4ms 4556 KiB
9 Hibás válasz 0/3 6ms 6068 KiB
10 Hibás válasz 0/3 7ms 7572 KiB
11 Hibás válasz 0/3 8ms 9060 KiB
12 Hibás válasz 0/3 9ms 10452 KiB
13 Hibás válasz 0/4 12ms 11800 KiB
14 Hibás válasz 0/4 14ms 13292 KiB
15 Hibás válasz 0/4 16ms 14624 KiB
16 Elfogadva 4/4 17ms 16252 KiB
17 Hibás válasz 0/4 19ms 17868 KiB