76752024-01-10 12:24:44madvirLegtávolabbi leszármazottcpp17Time limit exceeded 9/50400ms18044 KiB
#include <iostream>
#include <set>
#include <map>

using namespace std;

int main()
{
    int n, x, y;
    cin >> n;

    int a[n+1];
    map<int,int> fel;
    set<int> veg1, veg2;
    set<int>::iterator ptr;

    for(int i=0; i<n-1; i++) {
        cin >> x >> y;
        fel[y]=x;
        a[x]++;
        veg1.insert(y);
        veg2.insert(y);
    }

    int tart, card, max1=0, v;

    for(ptr=veg1.begin(); ptr!=veg1.end(); ptr++) {
        if(a[*ptr]>0) veg2.erase(*ptr);
    }

    for(ptr=veg2.begin(); ptr!=veg2.end(); ptr++) {
        tart=*ptr;
        card=0;
        while(fel[tart]>=1 && fel[tart]<=n) {
            card++;
            tart=fel[tart];
        }
        if(max1<card) {
            max1=card;
            v=*ptr;
        }
    }

    cout << v;




    return 0;
}
SubtaskSumTestVerdictTimeMemory
base9/50
1Accepted0/03ms1812 KiB
2Time limit exceeded0/0400ms14208 KiB
3Accepted1/13ms2168 KiB
4Wrong answer0/33ms2272 KiB
5Wrong answer0/33ms2360 KiB
6Wrong answer0/13ms2496 KiB
7Accepted1/13ms2732 KiB
8Accepted1/16ms3204 KiB
9Time limit exceeded0/2400ms16904 KiB
10Time limit exceeded0/3363ms17104 KiB
11Accepted3/33ms3572 KiB
12Time limit exceeded0/4400ms17208 KiB
13Time limit exceeded0/4363ms17504 KiB
14Accepted3/330ms6724 KiB
15Time limit exceeded0/3367ms16440 KiB
16Time limit exceeded0/3351ms15688 KiB
17Time limit exceeded0/3370ms16832 KiB
18Time limit exceeded0/4370ms13464 KiB
19Time limit exceeded0/4375ms15700 KiB
20Time limit exceeded0/4368ms18044 KiB