Picnic.cpp
991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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;
}