43912023-03-27 12:17:48AGergoLegtávolabbi leszármazottcpp14Time limit exceeded 21/50400ms13484 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;

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


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

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

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

    cout << index;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1832 KiB
2Accepted0/035ms11284 KiB
3Accepted1/13ms2256 KiB
4Accepted3/33ms2488 KiB
5Accepted3/33ms2704 KiB
6Accepted1/13ms2888 KiB
7Accepted1/13ms3092 KiB
8Accepted1/13ms3220 KiB
9Accepted2/239ms13484 KiB
10Accepted3/337ms13456 KiB
11Accepted3/33ms3564 KiB
12Time limit exceeded0/4400ms8444 KiB
13Time limit exceeded0/4363ms8820 KiB
14Accepted3/36ms4828 KiB
15Time limit exceeded0/3377ms8792 KiB
16Time limit exceeded0/3375ms8416 KiB
17Time limit exceeded0/3368ms8800 KiB
18Time limit exceeded0/4363ms7520 KiB
19Time limit exceeded0/4354ms8040 KiB
20Time limit exceeded0/4356ms9392 KiB