Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int N, M;
int arr[26][26];
int visited[26][26];
int maxLen;

void clear_visited() {
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			visited[i][j] = 0;
		}
	}
}

void dfs(int dinh, int len) {
	if (len > maxLen) maxLen = len;
	for (int i = 0; i < N; i++)
	{
		if (arr[dinh][i] == 1 && visited[dinh][i] == 0) {
			visited[dinh][i] = 1;
			visited[i][dinh] = 1;
			dfs(i, len + 1);
			visited[dinh][i] = 0;
			visited[i][dinh] = 0;
		}
		
	}	
}

void solution() {
	for (int i = 0; i < N; i++)
	{
		clear_visited();
		dfs(i, 0);
	}
}

int main() {
//	freopen("input.txt", "r", stdin);
	int u, v;
	int T;
	cin >> T;
	for (int tc = 1; tc <= T; tc++)
	{
		cin >> N >> M;
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N; j++)
			{
				arr[i][j] = 0;

			}
		}
		for (int i = 0; i < M; i++)
		{
			cin >> u >> v;
			arr[u][v] = 1;
			arr[v][u] = 1;
		}
		maxLen = 0;
		solution();
		cout << maxLen << endl;
	}
	return 0;
}