题目链接:传送门 一个无向图中求找到两个点使这两个点之间必须经过的边最多,求最多要经过的边
缩完点树的直径
E还能这么良心
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define
using namespace std;
typedef long long ll;
struct node {
int next, to;
}e[A], e2[A];
int head[A], num, head2[A], num2;
void add(int fr, int to) {
e[++num].next = head[fr];
e[num].to = to;
head[fr] = num;
}
void add2(int fr, int to) {
e2[++num2].next = head2[fr];
e2[num2].to = to;
head2[fr] = num2;
}
int dfn[A], low[A], sta[A], vis[A], cnt, top, kn, dis[A], n, m, a[A], b[A], bl[A];
void tarjan(int fr, int faa) {
dfn[fr] = low[fr] = ++cnt, sta[++top] = fr, vis[fr] = 1;
for (int i = head[fr]; i; i = e[i].next) {
int ca = e[i].to;
if (ca == faa) continue;
if (!dfn[ca]) tarjan(ca, fr), low[fr] = min(low[fr], low[ca]);
else if (vis[ca]) low[fr] = min(low[fr], dfn[ca]);
}
if (low[fr] == dfn[fr]) {
++kn;
int p;
do {
p = sta[top--];
vis[p] = 0;
bl[p] = kn;
} while (p != fr);
}
}
void dfs(int fr, int faa) {
for (int i = head2[fr]; i; i = e2[i].next) {
int ca = e2[i].to;
if (ca == faa) continue;
dis[ca] = dis[fr] + 1;
dfs(ca, fr);
}
}
int main(int argc, char const *argv[]) {
cin >> n >> m;
for (int i = 1; i <= m; i++) scanf("%d%d", &a[i], &b[i]), add(a[i], b[i]), add(b[i], a[i]);
for (int i = 1; i <= n; i++) if (!dfn[i]) tarjan(i, i);
for (int i = 1; i <= m; i++)
if (bl[a[i]] != bl[b[i]])
add2(bl[a[i]], bl[b[i]]), add2(bl[b[i]], bl[a[i]]);
dis[1] = 0; dfs(1, 0); int maxx = 0, pos = 1;
for (int i = 1; i <= n; i++) if (dis[i] > maxx) maxx = dis[i], pos = i;
memset(dis, 0, sizeof dis); dfs(pos, 0); int ans = 0;
for (int i = 1; i <= n; i++) ans = max(ans, dis[i]);
cout << ans << endl;
return 0;
}