73972024-01-08 13:51:04tamasmarkTársaság (50)cpp17Wrong answer 7/5019ms17868 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
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/03ms1876 KiB
2Wrong answer0/010ms9188 KiB
3Wrong answer0/33ms2564 KiB
4Wrong answer0/33ms2720 KiB
5Accepted3/33ms2848 KiB
6Wrong answer0/33ms3120 KiB
7Wrong answer0/33ms3536 KiB
8Wrong answer0/34ms4556 KiB
9Wrong answer0/36ms6068 KiB
10Wrong answer0/37ms7572 KiB
11Wrong answer0/38ms9060 KiB
12Wrong answer0/39ms10452 KiB
13Wrong answer0/412ms11800 KiB
14Wrong answer0/414ms13292 KiB
15Wrong answer0/416ms14624 KiB
16Accepted4/417ms16252 KiB
17Wrong answer0/419ms17868 KiB