43902023-03-27 12:16:03AGergoLegtávolabbi leszármazottcpp17Time 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;

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

    int maxi = 0;
    int index;

    for(int x : vegek)
    {
        if(maxi < veglen[x])
        {
            maxi = veglen[x];
            index = x;
        }
    }

    cout << index;
}
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/03ms1824 KiB
2Accepted0/035ms11320 KiB
3Accepted1/13ms2312 KiB
4Accepted3/33ms2444 KiB
5Accepted3/33ms2656 KiB
6Accepted1/13ms2868 KiB
7Accepted1/13ms2972 KiB
8Accepted1/13ms3112 KiB
9Accepted2/235ms13484 KiB
10Accepted3/337ms13436 KiB
11Accepted3/33ms3288 KiB
12Time limit exceeded0/4400ms8016 KiB
13Time limit exceeded0/4368ms8356 KiB
14Accepted3/36ms4620 KiB
15Time limit exceeded0/3400ms8640 KiB
16Time limit exceeded0/3372ms8400 KiB
17Time limit exceeded0/3360ms8768 KiB
18Time limit exceeded0/4331ms7552 KiB
19Time limit exceeded0/4379ms8152 KiB
20Time limit exceeded0/4363ms9652 KiB