10272022-02-25 08:10:55Szin AttilaKaktuszgráfcpp14Accepted 50/502ms2400 KiB
#include <bits/stdc++.h>
using namespace std;
#define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using ll = long long;

const int maxN = 2e5 + 5;
const int MOD = 1e9 + 7;

vector<vector<int> > g;
vector<bool> volt, elhagy;
vector<int> p;
int mo;

void visszafejt(int start, int end) {
    int ret = 1;
    int temp = start;
    while(temp != end) {
        ret++;
        temp = p[temp];
    }
    mo = max(mo, ret);
}

void dfs(int x) {
    volt[x] = 1;
    for(int sz : g[x]) {
        if(!volt[sz]) {
            p[sz] = x;
            dfs(sz);
        }
        else if(!elhagy[sz]) {
            visszafejt(x, sz);
        }
    }
    elhagy[x] = 1;
}

int main() {

#pragma region
#ifndef ONLINE_JUDGE
   freopen("../input.txt", "r", stdin);
   freopen("../output.txt", "w", stdout);
#endif

   InTheNameOfGod;
#pragma endregion
    
    int n,m;
    cin >> n >> m;

    g.resize(n+1);
    volt.resize(n+1, 0);
    elhagy.resize(n+1, 0);
    p.resize(n+1, -1);

    for(int i = 0; i < m; i++) {
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for(int i = 1; i <= n; i++) {
        if(!volt[i]) dfs(i);
    }

    cout << mo << "\n";

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1888 KiB
2Accepted0/01ms1900 KiB
3Accepted2/21ms1960 KiB
4Accepted2/21ms1980 KiB
5Accepted2/21ms1992 KiB
6Accepted2/21ms2008 KiB
7Accepted2/21ms2044 KiB
8Accepted2/21ms2032 KiB
9Accepted2/21ms2040 KiB
10Accepted2/22ms2056 KiB
11Accepted2/22ms2064 KiB
12Accepted2/22ms2080 KiB
13Accepted2/21ms2096 KiB
14Accepted2/22ms2100 KiB
15Accepted2/22ms2112 KiB
16Accepted2/21ms2132 KiB
17Accepted2/22ms2140 KiB
18Accepted2/22ms2164 KiB
19Accepted3/32ms2168 KiB
20Accepted3/31ms2356 KiB
21Accepted3/32ms2376 KiB
22Accepted3/31ms2384 KiB
23Accepted3/31ms2392 KiB
24Accepted3/31ms2400 KiB