Iamtui1010

duongdi.cpp

Mar 12th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<cstdlib>
  4.  
  5. #define long long long
  6.  
  7. using namespace std;
  8.  
  9. long n, m, ans = 0;
  10. vector<vector<long>> edg(10);
  11. vector<bool> tic(10, 0);
  12.  
  13. void dfs(long i, long cnt)
  14. {
  15.     if (cnt == n){
  16.         ++ans;
  17.         return;
  18.     }
  19.     for (const auto &j : edg[i])
  20.         if (!tic[j]){
  21.             tic[j] = 1;
  22.             dfs(j, cnt+1);
  23.             tic[j] = 0;
  24.         }
  25. }
  26.  
  27. int main()
  28. {
  29.     cin.tie(0)->sync_with_stdio(0);
  30.     cout.tie(0)->sync_with_stdio(0);
  31.     //freopen("duongdi.inp", "r", stdin);
  32.     cin >> n >> m;
  33.     while (m--){
  34.         long x, y;
  35.         cin >> x >> y;
  36.         edg[x].push_back(y);
  37.         edg[y].push_back(x);
  38.     }
  39.     tic[1] = 1;
  40.     dfs(1, 1);
  41.     cout << ans << '\n';
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment