The Settlers of Catan(dfs)

The Settlers of Catan


https://vjudge.net/contest/477179#problem/G

 

#include<iostream>
#include<cstring>
using namespace std;
int n,m,cmap[26][26],c[26][26],ans=0;
void dfs(int x,int l)
{
	ans=max(ans,l);
	for(int i=0;i<n;i++)
	{
		if(!c[x][i]&&cmap[x][i])
		{
			c[x][i]=c[i][x]=1;
			dfs(i,l+1);
			c[x][i]=c[i][x]=0;
		}
	}
}
int main()
{
	while(1)
	{
		cin>>n>>m;
		if(n==0&&m==0)return 0;
		ans=0;
		memset(cmap,0,sizeof cmap);
		memset(c,0,sizeof c);
		for(int i=0;i<m;i++)
		{
			int a,b;
			cin>>a>>b;
			cmap[a][b]=cmap[b][a]=1;
		}
		for(int i=0;i<n;i++)
		{
			dfs(i,0);
		}
		cout<<ans<<endl;
	}
}

 

posted @ 2022-04-08 23:02  是橙橙吖  Views(14)  Comments(0)    收藏  举报