35442023-02-28 20:52:29EyusieLegtávolabbi leszármazottcpp17Runtime error 13/50400ms22984 KiB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n, melyik, ki, hossz = 0, lnh = 0, osh, ind, tempind;
    cin >> n;
    vector<int> felmeno(n);
    set<int> leszarm, os;
    for(int i = 1; i < n+1; i++)
    {
        leszarm.insert(i);
        os.insert(i);
    }
    for(int i = 0; i < n-1; i++)
    {
        cin >> melyik >> ki;
        felmeno[ki] = melyik;
        leszarm.erase(melyik);
        os.erase(ki);
    }
    osh = *os.begin();
    int gen;
    for(auto itr = leszarm.begin(); itr != leszarm.end(); itr++)
        {
            gen = *itr;
            hossz = 0;
            tempind = gen;
            while(gen != osh)
            {
                gen = felmeno[gen];
                hossz++;
            }
            if(hossz > lnh)
            {
                lnh = hossz;
                ind = tempind;
            }
        }
        cout << ind;
}
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/03ms1940 KiB
2Accepted0/0202ms19472 KiB
3Runtime error0/13ms2512 KiB
4Runtime error0/33ms2756 KiB
5Runtime error0/33ms2820 KiB
6Accepted1/13ms2988 KiB
7Runtime error0/13ms3284 KiB
8Accepted1/14ms3612 KiB
9Accepted2/2188ms22984 KiB
10Accepted3/3185ms22940 KiB
11Accepted3/33ms3752 KiB
12Time limit exceeded0/4400ms12724 KiB
13Time limit exceeded0/4372ms12784 KiB
14Accepted3/317ms5900 KiB
15Time limit exceeded0/3370ms11980 KiB
16Time limit exceeded0/3372ms11612 KiB
17Time limit exceeded0/3352ms12364 KiB
18Time limit exceeded0/4356ms10372 KiB
19Time limit exceeded0/4356ms11656 KiB
20Time limit exceeded0/4384ms13256 KiB