Skip to content

Instantly share code, notes, and snippets.

@DonghoonPark12
Created April 5, 2019 13:49
Show Gist options
  • Save DonghoonPark12/f9d8ea2e971db1b044ff5047c7f7cf29 to your computer and use it in GitHub Desktop.
Save DonghoonPark12/f9d8ea2e971db1b044ff5047c7f7cf29 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
int ans;
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){
ans += 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 tc;
cin >> tc;
for (int t = 1; t <= tc; t++){
ans = 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 << ans << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment