93802024-02-21 11:27:29szilKaktuszgráfcpp17Accepted 50/503ms4332 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 1001;

vector<int> g[MAXN];
int d[MAXN], ans = 0;

void dfs(int u, int p = -1, int depth = 1) {
    d[u] = depth;
    for (int v : g[u]) {
        if (v != p) {
            if (d[v]) ans = max(ans, abs(d[v]-d[u]+1));
            else dfs(v, u, depth + 1);
        }
    }
}

void solve() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    dfs(1);
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1920 KiB
2Accepted0/03ms2260 KiB
3Accepted2/23ms2480 KiB
4Accepted2/23ms2428 KiB
5Accepted2/23ms2712 KiB
6Accepted2/23ms2992 KiB
7Accepted2/23ms2960 KiB
8Accepted2/23ms2884 KiB
9Accepted2/23ms2736 KiB
10Accepted2/23ms2740 KiB
11Accepted2/23ms3012 KiB
12Accepted2/23ms3184 KiB
13Accepted2/23ms3396 KiB
14Accepted2/23ms3352 KiB
15Accepted2/23ms3752 KiB
16Accepted2/23ms3796 KiB
17Accepted2/23ms3752 KiB
18Accepted2/23ms4048 KiB
19Accepted3/33ms3924 KiB
20Accepted3/33ms4104 KiB
21Accepted3/33ms4164 KiB
22Accepted3/33ms4236 KiB
23Accepted3/33ms4328 KiB
24Accepted3/33ms4332 KiB