21132022-12-20 10:22:00kicsiboglarKaktuszgráfcpp11Wrong answer 17/503ms4672 KiB
#include <iostream>
#define ll long long
#include <vector>
#include <deque>

using namespace std;

ll n,m,i,j,a,b,maxi=0;

struct element
{
    bool seen=false;
    vector <ll> sz;
};

vector <element> x;

deque <ll> v;

void DFS (ll curr)
{
    x[curr].seen=true;
    vector <ll>::iterator e;
    for (e=x[curr].sz.begin();e<x[curr].sz.end();++e)
    {
        if (!x[*e].seen)
        {
            v.push_front(*e);
            DFS(*e);
        }
        else
        {
            ll db=0;
            while(!v.empty()&&v[0]!=*e)
            {
                db++;
                v.pop_front();
            }
            if (db+1>maxi) maxi=db+1;
            if (e-x[curr].sz.begin()!=x[curr].sz.size()-1) v.push_front(curr);
        }
    }
    if (!v.empty()) v.pop_front();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

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

    v.push_back(1);
    DFS(1);
    cout<<maxi;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base17/50
1Accepted0/03ms1832 KiB
2Wrong answer0/02ms2220 KiB
3Accepted2/22ms2540 KiB
4Wrong answer0/22ms2752 KiB
5Wrong answer0/22ms2708 KiB
6Wrong answer0/22ms2968 KiB
7Wrong answer0/22ms2952 KiB
8Wrong answer0/22ms2904 KiB
9Wrong answer0/23ms3132 KiB
10Wrong answer0/23ms3340 KiB
11Wrong answer0/23ms3284 KiB
12Wrong answer0/23ms3552 KiB
13Wrong answer0/22ms3500 KiB
14Wrong answer0/23ms3756 KiB
15Wrong answer0/22ms3712 KiB
16Wrong answer0/22ms3712 KiB
17Wrong answer0/23ms3708 KiB
18Wrong answer0/23ms3708 KiB
19Wrong answer0/33ms3984 KiB
20Accepted3/33ms4312 KiB
21Accepted3/33ms4420 KiB
22Accepted3/33ms4468 KiB
23Accepted3/33ms4544 KiB
24Accepted3/33ms4672 KiB