33232023-02-25 14:44:38gkataLegtávolabbi leszármazottcpp17Accepted 50/5093ms17704 KiB
#include <iostream>
//#include <fstream>
#include <vector>
#include <deque>
#define ll long long

using namespace std;

//ifstream cin("in.in");
//ofstream cout("out.out");

struct csomopont
{
    int lat,lep,elso;
    vector<int>sz;
};
vector <csomopont>x;
deque <ll>v;

ll n,a,b,maxi=-1,sz,i,kezd,akt;
int main()
{
    cin>>n;
    x.resize(n+1);

    for(i=1;i<n;++i)
    {
        cin>>a>>b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
        x[b].elso=1;
    }

    for(i=1;i<=n;++i)
    {
        if(!x[i].elso)
            kezd=i;
    }

    v.push_back(kezd);
    x[kezd].lat=1;
    x[kezd].lep=0;
    while(!v.empty())
    {
        akt=v.front();
        v.pop_front();
        for(auto &e:x[akt].sz)
            if(!x[e].lat)
            {
                v.push_back(e);
                x[e].lat=1;
                x[e].lep=x[akt].lep+1;
                if(x[e].lep>maxi)
                {
                    maxi=x[e].lep;
                    sz=e;
                }
            }
    }
    cout<<sz;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/082ms14796 KiB
3Accepted1/13ms2232 KiB
4Accepted3/33ms2328 KiB
5Accepted3/32ms2412 KiB
6Accepted1/13ms2668 KiB
7Accepted1/13ms2636 KiB
8Accepted1/13ms2952 KiB
9Accepted2/286ms17440 KiB
10Accepted3/390ms17704 KiB
11Accepted3/33ms3332 KiB
12Accepted4/490ms17260 KiB
13Accepted4/490ms17264 KiB
14Accepted3/39ms4832 KiB
15Accepted3/387ms16040 KiB
16Accepted3/379ms15392 KiB
17Accepted3/393ms16432 KiB
18Accepted4/464ms13440 KiB
19Accepted4/478ms15260 KiB
20Accepted4/493ms17684 KiB