Iamtui1010

dattam.cpp

Sep 28th, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<climits>
  4.  
  5. #define long long long
  6. #define nln '\n'
  7.  
  8. using namespace std;
  9.  
  10. void put(long idx, long n, vector<bool> &p, const vector<vector<long>> a, long cnt, long &res)
  11. {
  12.     if (idx > n){
  13.         //check to take result
  14.         bool chk = 1;
  15.         for (long i = 1; i <= n; ++i){
  16.             if (p[i])
  17.                 continue;
  18.             chk = 0;
  19.             for (auto j : a[i])
  20.                 if (p[j]){
  21.                     chk = 1;
  22.                     break;
  23.                 }
  24.             if (!chk)
  25.                 break;
  26.         }
  27.         res = (chk && cnt < res) ? cnt : res;
  28.         return;
  29.     }
  30.     put(idx+1, n, p, a, cnt, res);
  31.     p[idx] = 1;
  32.     put(idx+1, n, p, a, cnt+1, res);
  33.     p[idx] = 0;
  34. }
  35.  
  36. int main()
  37. {
  38.     cin.tie(0)->sync_with_stdio(0);
  39.     freopen("dattam.inp", "r", stdin);
  40.     freopen("dattam.out", "w", stdout);
  41.     long n, m;
  42.     cin >> n >> m;
  43.     vector<vector<long>> a(n+1);
  44.     for (long i = 0; i < m; ++i){
  45.         long x, y;
  46.         cin >> x >> y;
  47.         a[x].push_back(y);
  48.         a[y].push_back(x);
  49.     }
  50.     vector<bool> p(n+1, 0);
  51.     long res = n;
  52.     put(1, n, p, a, 0, res);
  53.     cout << res;
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment