999ms

Untitled

Nov 27th, 2021 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. #pragma GCC Optimaze("Ofast")
  2. #pragma GCC target("avx,avx2")
  3.  
  4. #include <bits/stdc++.h>
  5.  
  6. #define all(x) (x).begin(),(x).end()
  7.  
  8. const int N = 3e4;
  9.  
  10. using namespace std;
  11. using bs = bitset<N>;
  12.  
  13. bs g[N];
  14. int n;
  15. bool used[N];
  16. bool matched[N];
  17. int mt[N];
  18.  
  19. bool Inc(int v) {
  20.     if (used[v]) return false;
  21.     used[v] = true;
  22.     for (auto i = g[v]._Find_first(); i < n; i = g[v]._Find_next(i)) {
  23.         if (mt[i] == -1) {
  24.             matched[v] = true;
  25.             mt[i] = v;
  26.             return true;
  27.         }
  28.     }
  29.     for (auto i = g[v]._Find_first(); i < n; i = g[v]._Find_next(i)) {
  30.         if (Inc(mt[i])) {
  31.             matched[v] = true;
  32.             mt[i] = v;
  33.             return true;
  34.         }
  35.     }
  36.     return false;
  37. }
  38.  
  39. mt19937 rnd(random_device{}());
  40.  
  41. int GetMT() {
  42.     memset(matched, 0, sizeof matched);
  43.     fill(mt, mt + N, -1);
  44.     int cur = 0;
  45.     vector<int> indexes(n);
  46.     iota(all(indexes), 0);
  47.     for (int run = 1; run;) {
  48.         run = 0;
  49.         shuffle(all(indexes), rnd);
  50.         memset(used, 0, sizeof used);
  51.         for (int i: indexes) {
  52.             if (!matched[i] && Inc(i)) {
  53.                 cur++;
  54.                 run = 1;
  55.             }
  56.         }
  57.     }
  58.     return cur;
  59. }
  60.  
  61. int main() {
  62.     ios_base::sync_with_stdio(false);
  63.     cin.tie(nullptr);
  64.     cout.tie(nullptr);
  65.  
  66. }
Add Comment
Please, Sign In to add comment