#include<bits/stdc++.h>
const int N=1145140;
using namespace std;
int cnt,dfn_cnt,sc_cnt,new_cnt,cnt_bridge,ccnt;
int head[N],low[N],dfn[N],inst[N];
int nhead[N],nw[N],rid[N];
int sc[N],p[N],in[N],ch[N],dp[N],sum[N],vis[N],f[N],bri[N];
int n,m,M,Max,Max2;
stack<int> st;
struct node{
int u,v,w;
}a[N];
struct node2{
int u,v;
}b[N];
struct edge{
int to,next;
}e[N];
void add_edge(int u,int v){
e[++cnt].to=v;
e[cnt].next=head[u];
head[u]=cnt;
}
struct edge2{
int to,next;
}ne[N];//缩点后的图
void add_edge2(int u,int v){
ne[++new_cnt].to=v;
ne[new_cnt].next=nhead[u];
nhead[u]=new_cnt;
}
bool cmp(node2 x,node2 y){
if(x.u==y.u) return x.v<y.v;
return x.u<y.u;
}
void tarjan(int s,int last){
dfn[s]=low[s]=++dfn_cnt;
for(int i=head[s];i;i=e[i].next){
int v=e[i].to;
if(i==(last^1)) continue;
if(!dfn[v]){
tarjan(v,i);
low[s]=min(low[s],low[v]);
if(dfn[s]<=low[v]){bri[i]=bri[i^1]=1;}//桥
}
else low[s]=min(low[s],dfn[v]);
}
}
void dfs_0(int s){
rid[s]=ccnt;
for(int i=head[s];i;i=e[i].next){
int v=e[i].to;
if(bri[i]||rid[v]) continue;
dfs_0(v);
}
}
void dfs(int u){//求树的直径
vis[u]=1;
//cout<<"u:"<<u<<endl;
for(int i=nhead[u];i;i=ne[i].next){
int v=ne[i].to;
if(vis[v]) continue;
dp[v]=dp[u]+1;
//cout<<"dp"<<dp[v]<<endl;
if(dp[v]>=dp[Max]) Max=v;
dfs(v);
}
return ;
}
void dfs2(int u){
vis[u]=1;
//cout<<"u2: "<<u<<endl;
for(int i=nhead[u];i;i=ne[i].next){
int v=ne[i].to;
if(vis[v]) continue;
dp[v]=dp[u]+1;
if(dp[v]>=dp[Max2]) {
Max2=v;
}
dfs2(v);
}
return ;
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>a[i].u>>a[i].v;
add_edge(a[i].u,a[i].v);
add_edge(a[i].v,a[i].u);
}
tarjan(1,-1);
for(int i=1;i<=n;i++)
if(!rid[i]){ccnt++;dfs_0(i);}
for(int s=1;s<=n;s++)
for(int i=head[s];i;i=e[i].next)
if(rid[s]!=rid[e[i].to]){
//cout<<"rid: "<<rid[s]<<" "<<rid[e[i].to]<<endl;
add_edge2(rid[s],rid[e[i].to]);
}
dfs(1);
memset(dp,0,sizeof(dp));
memset(vis,0,sizeof(vis));
dfs2(Max);
int ans=0;
for(int i=1;i<=n;i++){
ans=max(ans,dp[i]);
}
cout<<ans;
return 0;
}
对拍拍出了很多错误样例,但我没调出来