43892023-03-27 12:12:42AGergoLegtávolabbi leszármazottcpp17Wrong answer 1/50400ms13316 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{

    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;

    }
    /*for(int x : apja)
    {
        cout << x << " " ;
    }
    cout << "\n";

    int os;

    for(int i = 1; i < len; i++)
    {
        if(apja[i] == -1)
        {
            os = i;
            break;
        }
    }*/

    vector<int> vegek;

    vector<int> veglen;


    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];
            num++;
        }
        veglen.push_back(num);
    }

    int maxi = 0;
    int index;

    for(int i = 0; i < veglen.capacity();i++)
    {
        if(maxi < veglen[i])
        {
            maxi = veglen[i];
            index = vegek[i];
        }
    }

    cout << index;
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/03ms1808 KiB
2Wrong answer0/068ms10872 KiB
3Accepted1/13ms2312 KiB
4Wrong answer0/33ms2428 KiB
5Wrong answer0/33ms2636 KiB
6Wrong answer0/13ms2856 KiB
7Wrong answer0/13ms3072 KiB
8Wrong answer0/13ms3472 KiB
9Wrong answer0/274ms13084 KiB
10Wrong answer0/372ms13316 KiB
11Wrong answer0/33ms3724 KiB
12Time limit exceeded0/4400ms8392 KiB
13Time limit exceeded0/4354ms8364 KiB
14Wrong answer0/38ms5072 KiB
15Time limit exceeded0/3379ms8780 KiB
16Time limit exceeded0/3340ms8308 KiB
17Time limit exceeded0/3368ms8508 KiB
18Time limit exceeded0/4375ms7380 KiB
19Time limit exceeded0/4368ms7892 KiB
20Time limit exceeded0/4381ms9336 KiB