20352022-12-15 13:01:46kicsiboglarKaktuszgráfcpp11Wrong answer 23/503ms4348 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);
    }

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

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base23/50
1Accepted0/03ms1824 KiB
2Wrong answer0/02ms2228 KiB
3Accepted2/22ms2136 KiB
4Accepted2/23ms2472 KiB
5Accepted2/23ms2616 KiB
6Wrong answer0/23ms2828 KiB
7Accepted2/23ms3060 KiB
8Wrong answer0/22ms2984 KiB
9Wrong answer0/23ms3268 KiB
10Wrong answer0/23ms3592 KiB
11Wrong answer0/23ms3636 KiB
12Wrong answer0/23ms3664 KiB
13Wrong answer0/23ms3564 KiB
14Wrong answer0/22ms3560 KiB
15Wrong answer0/23ms3716 KiB
16Wrong answer0/23ms3672 KiB
17Wrong answer0/23ms3692 KiB
18Wrong answer0/23ms3584 KiB
19Wrong answer0/33ms3844 KiB
20Accepted3/32ms4036 KiB
21Accepted3/32ms4140 KiB
22Accepted3/32ms4136 KiB
23Accepted3/32ms4264 KiB
24Accepted3/33ms4348 KiB