20342022-12-15 12:53:15kicsiboglarKaktuszgráfcpp11Wrong answer 25/503ms4920 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;
    ll intime,outtime;
};

vector <element> x;

deque <ll> v;

void DFS (ll curr,ll step)
{
    x[curr].seen=true;
    x[curr].intime=step;
    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,step+1);
        }
        else if (!x[*e].outtime&&x[*e].intime<x[curr].intime)
        {
            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);
        }
    }
    x[curr].outtime=step;
}

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,1);
    cout<<maxi;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1824 KiB
2Wrong answer0/02ms2236 KiB
3Accepted2/22ms2408 KiB
4Accepted2/22ms2616 KiB
5Accepted2/22ms2444 KiB
6Wrong answer0/23ms2712 KiB
7Accepted2/22ms2820 KiB
8Wrong answer0/22ms2920 KiB
9Accepted2/23ms3188 KiB
10Wrong answer0/23ms3540 KiB
11Wrong answer0/23ms3784 KiB
12Wrong answer0/23ms3796 KiB
13Wrong answer0/23ms3756 KiB
14Wrong answer0/23ms3752 KiB
15Wrong answer0/23ms3696 KiB
16Wrong answer0/23ms4108 KiB
17Wrong answer0/23ms4280 KiB
18Wrong answer0/23ms4356 KiB
19Wrong answer0/33ms4504 KiB
20Accepted3/33ms4664 KiB
21Accepted3/33ms4920 KiB
22Accepted3/33ms4792 KiB
23Accepted3/32ms4672 KiB
24Accepted3/33ms4668 KiB