[cpp] #include<stdio.h> #include<string.h> int map[26][26],vis[26][26]; int n,m,pathmax; void dfs(int i,int d) { if(d>pathmax) pathmax=d; for(int j=0;j<n;j++) { if(!vis[j][i]&&!vis[i][j]&&map[i][j]&&i!=j) { vis[i][j]=vis[j][i]=1; dfs(j,d+1); vis[i][j]=vis[j][i]=0; } } } int main() { int i,x,y; while(scanf("%d%d",&n,&m)==2&&n&&m) { memset(map,0,sizeof(map)); for(i=0;i<m;i++) { scanf("%d%d",&x,&y); map[x][y]=map[y][x]=1; } pathmax=0; for(i=0;i<n;i++) { memset(vis,0,sizeof(vis)); dfs(i,0); } printf("%d\n",pathmax); } return 0; }