Iamtui1010

dattam.cpp

Sep 16th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<fstream>
  3. #include<vector>
  4. #include<iostream>
  5. #include <climits>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. const long N = 45;
  11.  
  12. using namespace std;
  13.  
  14. fstream f1, f2;
  15.  
  16. inline void openf()
  17. {
  18.     f1.open("dattam.inp", ios:: in);
  19.     f2.open("dattam.out", ios:: out);
  20. }
  21.  
  22. inline void closef()
  23. {
  24.     f1.close();
  25.     f2.close();
  26. }
  27.  
  28. long m, n;
  29. vector<vector<long>> a(N);
  30.  
  31. void data()
  32. {
  33.     cin >> n >> m;
  34.     for (long i = 0; i != m; ++i)
  35.     {
  36.         long x, y;
  37.         cin >> x >> y;
  38.         a[x].push_back(y);
  39.         a[y].push_back(x);
  40.     }
  41. }
  42.  
  43. vector<bool> cen(N, 0);
  44. long mic = SHRT_MAX;
  45.  
  46. void build(long i)
  47. {
  48.     if (i > n)
  49.     {
  50.         long ok = 1;
  51.         for (long j = 1; j-1 != n; ++j)
  52.             if (!cen[j])
  53.             {
  54.                 long sat = 0;
  55.                 for (const auto &u : a[j])
  56.                     if (cen[u])
  57.                     {
  58.                         sat = 1;
  59.                         break;
  60.                     }
  61.                 if (!sat)
  62.                 {
  63.                     ok = 0;
  64.                     break;
  65.                 }
  66.             }
  67.         if (ok)
  68.         {
  69.             long coc = 0;
  70.             for (long i = 1; i-1 != n; ++i)
  71.                 if (cen[i])
  72.                     ++coc;
  73.             if (coc < mic)
  74.                 mic = coc;
  75.         }
  76.         return;
  77.     }
  78.  
  79.     bool put = 0;
  80.     if (cen[i])
  81.         put = 1;
  82.     else
  83.     {
  84.         for (const auto &j : a[i])
  85.             if (cen[j])
  86.             {
  87.                 put = 1;
  88.                 break;
  89.             }
  90.     }
  91.     if (put == 0)
  92.     {
  93.         build(i+1);
  94.         cen[i] = 1;
  95.         build(i+1);
  96.         cen[i] = 0;
  97.     }
  98.     else
  99.         build(i+1);
  100. }
  101.  
  102. void process()
  103. {
  104.     build(1);
  105. }
  106.  
  107. void view()
  108. {
  109.     cout << mic << nln;
  110. }
  111.  
  112. int main()
  113. {
  114.     //cout << "Le Duc Phuc Long" << endl;
  115.     openf();
  116.     data();
  117.     process();
  118.     view();
  119.     closef();
  120.     return 0;
  121. }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment