Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<queue>
  6.  
  7. using namespace std;
  8.  
  9. #define SIZE 10
  10.  
  11. int n, m; // 학생 수, 친구 쌍의 수
  12. bool arr[SIZE][SIZE];
  13. bool cnn[SIZE];
  14.  
  15.  
  16. void init() {
  17. for (int i = 0; i < SIZE; i++) {
  18. cnn[i] = 0;
  19. for (int j = 0; j < SIZE; j++) {
  20. arr[i][j] = 0;
  21. }
  22. }
  23. }
  24.  
  25. int connectFriends(int idx) {
  26. int ret = 0;
  27. if (idx >= n) {
  28. return 1;
  29. }
  30.  
  31. if (cnn[idx]) return connectFriends(idx+1);
  32.  
  33. for (int i = idx+1; i < n; i++) {
  34. if (cnn[i]) continue;
  35. if (!arr[idx][i]) continue;
  36. cnn[i] = true;
  37. ret+=connectFriends(idx+1);
  38. cnn[i] = false;
  39. }
  40.  
  41. return ret;
  42. }
  43.  
  44.  
  45. void solve() {
  46. init();
  47. scanf("%d %d", &n, &m);
  48.  
  49. for (int i = 0; i < m; i++) {
  50. int f1, f2;
  51. scanf("%d %d", &f1, &f2);
  52. arr[f1][f2] = arr[f2][f1] = 1;
  53. }
  54.  
  55. printf("%d\n", connectFriends(0));
  56. }
  57.  
  58.  
  59.  
  60. int main() {
  61. int testCase;
  62. scanf("%d", &testCase);
  63.  
  64. for (int i = 0; i < testCase; i++) {
  65. solve();
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement