95242024-02-22 14:24:59Vkrisztian01Kaktuszgráfcpp17Accepted 50/506ms3872 KiB
#include <iostream>
#include<vector>
#include<stack>
#include<algorithm>

using namespace std;

vector<int>akt;
vector<int>ki;
int n,m,a,b,db,maxdb=0;
vector<vector<bool> > g;
vector<bool>jarte;
vector<int> csucsok;
vector<int>aktkor;

void dfs(int node)
{
    jarte[node]=true;
    csucsok.push_back(node);
    for(int to=1;to<=n;to++)
    {
        if(!g[node][to]) continue;
        if(!jarte[to])
        {
            g[node][to]=false;
            g[to][node]=false;
            dfs(to);
            continue;
        }
        int i=csucsok.size()-1;
        db=1;
        while(csucsok[i]!=to)
        {
            ++db;
            --i;
        }
        maxdb=max(db,maxdb);
    }
    jarte[node]=false;
    csucsok.pop_back();
}



int main()
{
    cin>>n>>m;
    g.assign(n+1,vector<bool>(n+1,false));
    jarte.assign(n+1,false);
    while(m--)
    {
        cin>>a>>b;
        g[a][b]=true;
        g[b][a]=true;
    }
    dfs(1);
    cout<<maxdb;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/04ms2248 KiB
3Accepted2/24ms2292 KiB
4Accepted2/24ms2280 KiB
5Accepted2/24ms2308 KiB
6Accepted2/24ms2596 KiB
7Accepted2/24ms2732 KiB
8Accepted2/24ms2712 KiB
9Accepted2/26ms2708 KiB
10Accepted2/26ms2964 KiB
11Accepted2/26ms3044 KiB
12Accepted2/26ms3296 KiB
13Accepted2/26ms3504 KiB
14Accepted2/26ms3348 KiB
15Accepted2/26ms3348 KiB
16Accepted2/26ms3352 KiB
17Accepted2/26ms3348 KiB
18Accepted2/26ms3684 KiB
19Accepted3/36ms3644 KiB
20Accepted3/34ms3764 KiB
21Accepted3/34ms3772 KiB
22Accepted3/34ms3872 KiB
23Accepted3/34ms3872 KiB
24Accepted3/34ms3772 KiB