#include<iostream>
using namespace std;
int a[30][30];
int n, m, cnt;
int visit[30][30] = {0};
int Answer;
int num[30];
void DFS(int x,int cnt)
{
if( Answer < cnt)
Answer = cnt;
for(int i = 0; i < n ; i++)
{
if(visit[x][i] == 0 && a[x][i] == 1)
{
visit[x][i] = 1;
visit[i][x] = 1;
//cnt++;
DFS(i,cnt+1);
visit[x][i] = 0;
visit[i][x] = 0;
//cnt--;
}
}
}
int main()
{
int test_case;
int T;
ios::sync_with_stdio(false);
freopen("input.txt", "r", stdin);
cin >> T;
for(test_case = 1; test_case <= T; ++test_case)
{
Answer = 0;
//cnt=0;
cin >> n >> m;
int x, y;
for(int i = 0; i< n; i++)
for(int j = 0; j< n; j++)
a[i][j] = 0;
for(int i = 0; i < m; i++)
{
cin >> x >> y;
num[x]++;
num[y]++;
a[x][y] = 1;
a[y][x] = 1;
}
for(int i = 0; i < n; i++){
//cnt = 0;
DFS(i,0);
}
cout << Answer << endl;
}
return 0;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.