Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
#include <iostream>
using namespace std;

int arr[26][26];
int ar[26][26];

void timduong(int &max, int i, int cnt, int N)
{
	int dk = 0;
	for(int j = 0; j < N; j++)
	{
		if(arr[i][j] != -1 && ar[i][j] == -1 )
		{
			dk = 1;
			ar[i][j] = 1;
			ar[j][i] = 1;
			timduong(max, j, cnt + 1, N);
			ar[i][j] = -1;
			ar[j][i] = -1;
		}
	}
	if(dk == 0)
	{
		if(max < cnt)
		{
			max = cnt;
		}
	}
}

int main()
{
	//freopen("input.txt", "r+", stdin);
	int testcase;
	cin >> testcase;
	for(int tc= 1; tc <= testcase; tc++)
	{
		int N, M;
		cin >> N >> M;
		int max = 0;
		for(int i = 0; i < 26; i++)
		{
			for(int j = 0; j < 26; j++)
			{
				arr[i][j] = -1;
				ar[i][j] = -1;
			}
		}
		for(int i = 0; i < M; i++)
		{
			int x, y;
			cin >> x >> y;
			arr[x][y] = 1;
			arr[y][x] = 1;
		}
		for(int i = 0; i < N; i++)
		{
			for(int t = 0; t < 26; t++)
		    {
			    for(int j = 0; j < 26; j++)
			    {
				    ar[t][j] = -1;
			    }
		    }
			timduong(max , i, 0, N);
		}
		cout<<max<<endl;
	}
}