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

int main()
{
    cin.tie();
    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/03ms1808 KiB
2Accepted0/0202ms19396 KiB
3Runtime error0/13ms2392 KiB
4Runtime error0/33ms2524 KiB
5Runtime error0/33ms2800 KiB
6Accepted1/13ms2824 KiB
7Runtime error0/13ms3132 KiB
8Accepted1/14ms3408 KiB
9Accepted2/2184ms22408 KiB
10Accepted3/3197ms22452 KiB
11Accepted3/33ms3208 KiB
12Time limit exceeded0/4400ms12436 KiB
13Time limit exceeded0/4384ms12340 KiB
14Accepted3/317ms5516 KiB
15Time limit exceeded0/3374ms11784 KiB
16Time limit exceeded0/3372ms11640 KiB
17Time limit exceeded0/3356ms12060 KiB
18Time limit exceeded0/4368ms9960 KiB
19Time limit exceeded0/4347ms11376 KiB
20Time limit exceeded0/4360ms12964 KiB