-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjongmanbook(158).cpp
More file actions
59 lines (56 loc) · 1.25 KB
/
jongmanbook(158).cpp
File metadata and controls
59 lines (56 loc) · 1.25 KB
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
#include <iostream>
#include <cstring>
using namespace std;
int n;
bool areFriends[10][10];
int countPairings(bool taken[10])
{
int firstFree = -1;
for (int i = 0; i < n; i++)
{
if (!taken[i])
{
firstFree = i;
break;
}
}
if (firstFree == -1)
return 1;
int ret = 0;
for (int pairWith = firstFree + 1; pairWith < n; pairWith++)
{
if (!taken[pairWith] && areFriends[firstFree][pairWith])
{
taken[firstFree] = taken[pairWith] = true;
ret += countPairings(taken);
taken[firstFree] = taken[pairWith] = false;
}
}
return ret;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int count;
cin >> count;
while (count--)
{
int pairofStudents;
cin >> n >> pairofStudents;
while (pairofStudents--)
{
int tmp1, tmp2;
cin >> tmp1 >> tmp2;
areFriends[tmp1][tmp2] = true;
areFriends[tmp2][tmp1] = true;
}
bool freinds[10] = {
0,
};
int answer = countPairings(freinds);
cout << answer << "\n";
memset(areFriends, 0, sizeof(areFriends));
}
}