Picnic.cpp 991 Bytes
#include<iostream>

using namespace std;

int result;
int N, M;
bool areFriends[10][10];
bool havePair[10];

void counting(int n)
{
	bool finished = true;
	int first = -1;
	for (int i = 0;i < N;i++)
	{
		if (!havePair[i])
		{
			finished = false;
			first = i;
			break;
		}
	}

	if (finished)
	{
		result += 1;
		return;
	}

	for (int j = first + 1;j < N;j++)
	{
		if (!havePair[first] && !havePair[j] && areFriends[first][j])
		{
			havePair[first] = true;
			havePair[j] = true;
			counting(n+1);
			havePair[first] = false;
			havePair[j] = false;
		}
	}

	return;
}

int main()
{
	int test;
	cin >> test;

	for (int t = 1;t <= test;t++)
	{
		result = 0;
		for (int i = 0;i < 10;i++)
		{
			havePair[i] = false;
			for (int j = 0;j < 10;j++)
			{
				areFriends[i][j] = false;
			}
		}

		cin >> N >> M;

		for (int i = 0;i < M;i++)
		{
			int a, b;
			cin >> a >> b;
			areFriends[a][b] = true;
			areFriends[b][a] = true;
		}

		counting(0);

		cout << result << endl;
	}

	return 0;
}