106862024-04-08 22:28:44VargusLegtávolabbi leszármazottcpp17Accepted 50/5098ms38096 KiB
#include <iostream>
#include <queue>
#define ll long long

using namespace std;

struct adat
{
    ll ido, ut;
    bool lat = false;
    vector <ll> sz;
};
vector <adat> x;

void melyseg(ll csp)
{
    x[csp].lat = true;
    for (auto& e : x[csp].sz)
    {
        x[e].ido += 1 + x[csp].ido;
        if (!x[e].lat)
        {
            melyseg(e);
        }
    }
}

int main()
{
    ll n;
    cin >> n;
    x.resize(n + 1);
    for (ll i = 1; i <= n-1; ++i)
    {
        ll cs1, cs2;
        cin >> cs1 >> cs2;
        x[cs1].sz.push_back(cs2);
        x[cs2].ut = cs1;
    }
    for (ll i = 1; i <= n; ++i)
    {
        if (!x[i].ut)
        {
            melyseg(i);
            break;
        }
    }
    ll maxpoz = -1, maxi = -9999999;
    for (ll i = 1; i <= n; ++i)
    {
        if (x[i].ido > maxi)
        {
            maxi = x[i].ido;
            maxpoz = i;
        }
    }
    cout << maxpoz;

    return 0;
}
/*
8
1 4
5 7
8 6
8 5
3 1
3 2
3 8
*/
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1876 KiB
2Accepted0/079ms14432 KiB
3Accepted1/13ms3032 KiB
4Accepted3/33ms3044 KiB
5Accepted3/33ms3276 KiB
6Accepted1/13ms3388 KiB
7Accepted1/13ms3636 KiB
8Accepted1/13ms3756 KiB
9Accepted2/286ms17764 KiB
10Accepted3/389ms18888 KiB
11Accepted3/33ms6100 KiB
12Accepted4/492ms25420 KiB
13Accepted4/494ms26696 KiB
14Accepted3/39ms9864 KiB
15Accepted3/386ms27096 KiB
16Accepted3/381ms28660 KiB
17Accepted3/390ms29116 KiB
18Accepted4/463ms25028 KiB
19Accepted4/476ms29732 KiB
20Accepted4/498ms38096 KiB