20332022-12-15 12:48:38kicsiboglarKaktuszgráfcpp11Wrong answer 23/503ms4184 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);
        }
    }
}

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);
    }

    DFS(1);
    cout<<maxi;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1832 KiB
2Wrong answer0/02ms2220 KiB
3Accepted2/22ms2268 KiB
4Accepted2/22ms2588 KiB
5Accepted2/23ms2900 KiB
6Wrong answer0/23ms3108 KiB
7Accepted2/22ms3092 KiB
8Wrong answer0/22ms3236 KiB
9Wrong answer0/23ms3080 KiB
10Wrong answer0/23ms3084 KiB
11Wrong answer0/23ms3340 KiB
12Wrong answer0/23ms3552 KiB
13Wrong answer0/22ms3496 KiB
14Wrong answer0/23ms3748 KiB
15Wrong answer0/23ms4032 KiB
16Wrong answer0/23ms3904 KiB
17Wrong answer0/23ms3900 KiB
18Wrong answer0/23ms3900 KiB
19Wrong answer0/33ms4080 KiB
20Accepted3/32ms4184 KiB
21Accepted3/32ms4108 KiB
22Accepted3/32ms4108 KiB
23Accepted3/32ms4180 KiB
24Accepted3/33ms4184 KiB