43942023-03-27 12:45:36AGergoLegtávolabbi leszármazottcpp11Time limit exceeded 21/50400ms12376 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);

    int len;
    cin >> len;

    vector<vector<int>> fia (len+1,vector<int>());
    vector<int> apja(len+1,-1);

    int t1,t2;

    for(int i = 0; i < len-1; i++)
    {
       cin >> t1 >> t2;

       fia[t1].push_back(t2);
       apja[t2] = t1;

    }

    vector<int> vegek;

    for(int i = 1; i < len; i++)
    {
        if(fia[i].size() == 0)
        {
            vegek.push_back(i);
        }
    }

    int k;
    int num = 0;
    int maxi = 0;
    int index;

    for(int x : vegek)
    {
        k = x;
        num = 0;
        while(apja[k] != -1)
        {
            k = apja[k];
            num++;
        }
        if(maxi < num)
        {
            maxi = num;
            index = x;
        }
    }

    cout << index;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1696 KiB
2Accepted0/032ms10548 KiB
3Accepted1/12ms1944 KiB
4Accepted3/33ms2080 KiB
5Accepted3/33ms2288 KiB
6Accepted1/13ms2476 KiB
7Accepted1/13ms2872 KiB
8Accepted1/13ms3232 KiB
9Accepted2/235ms12376 KiB
10Accepted3/335ms12360 KiB
11Accepted3/33ms3312 KiB
12Time limit exceeded0/4400ms7660 KiB
13Time limit exceeded0/4375ms7564 KiB
14Accepted3/34ms4200 KiB
15Time limit exceeded0/3365ms7596 KiB
16Time limit exceeded0/3363ms7468 KiB
17Time limit exceeded0/3351ms7684 KiB
18Time limit exceeded0/4347ms6944 KiB
19Time limit exceeded0/4363ms7504 KiB
20Time limit exceeded0/4368ms8868 KiB