| 记录编号 | 
        442537 | 
        评测结果 | 
        AAAAAAAAAA | 
    
    
        | 题目名称 | 
        417.[HAOI 2009]毛毛虫 | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         CSU_Turkey | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        C++ | 
        运行时间 | 
        0.594 s  | 
    
    
        | 提交时间 | 
        2017-08-27 18:52:26 | 
        内存使用 | 
        6.04 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		#include<bits/stdc++.h>
using namespace std;
int n,m,f[300005],ma=-1,vis[300005];
vector<int>a[300005];
void dfs(int x){
	vis[x]=1;
	int tem1=0,tem2=0,c=0;
	int u=a[x].size();
	for(int i=0;i<u;i++){
		if(vis[a[x][i]])continue;
		dfs(a[x][i]);
		f[x]=max((f[a[x][i]]+u-1),f[x]);
		if(tem1<f[a[x][i]]){
			tem1=f[a[x][i]];
			c=a[x][i];
		}
	}
	for(int i=0;i<a[x].size();i++){
		if(tem2<f[a[x][i]]&&a[x][i]!=c)
		tem2=f[a[x][i]];
	}
	ma=max(tem1+tem2+u-1,ma);
}
int main()
{
	freopen("worma.in","r",stdin);
	freopen("worma.out","w",stdout);
//	freopen("1.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	f[i]=1;
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1);
	cout<<ma;
	return 0;
}