9252022-01-28 13:46:13Valaki2Kaktuszgráfcpp14Accepted 50/5025ms2384 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int maxn = 1000;

int n, m;
vector<int> g[maxn + 1];
bool vis[maxn + 1];
int ans;

void dfs(int x, int d, int s) {
    if(vis[x]) {
        if(x == s && d != 0) {
            ans = max(ans, d);
        }
        return;
    }
    vis[x] = true;
    for(int y : g[x]) {
        dfs(y, d + 1, s);
    }
}

void solve() {
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            vis[j] = false;
        }
        dfs(i, 0, i);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/02ms1840 KiB
2Accepted0/04ms2040 KiB
3Accepted2/26ms1984 KiB
4Accepted2/28ms2004 KiB
5Accepted2/212ms2020 KiB
6Accepted2/216ms2024 KiB
7Accepted2/217ms2060 KiB
8Accepted2/213ms2048 KiB
9Accepted2/218ms2052 KiB
10Accepted2/220ms2072 KiB
11Accepted2/219ms2076 KiB
12Accepted2/225ms2092 KiB
13Accepted2/216ms2104 KiB
14Accepted2/218ms2112 KiB
15Accepted2/218ms2124 KiB
16Accepted2/225ms2140 KiB
17Accepted2/220ms2156 KiB
18Accepted2/218ms2172 KiB
19Accepted3/323ms2180 KiB
20Accepted3/320ms2240 KiB
21Accepted3/321ms2376 KiB
22Accepted3/323ms2384 KiB
23Accepted3/323ms2384 KiB
24Accepted3/321ms2268 KiB