Advertisement
999ms

Untitled

Aug 15th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. bool used[MSIZE];
  2. bool matched[MSIZE];
  3. int mt[MSIZE];
  4. vector<int> g[MSIZE];
  5.  
  6. int Inc(int v) {
  7.     if (used[v]) return false;
  8.     used[v] = true;
  9.     for (int nxt : g[v]) {
  10.         if (mt[nxt] == -1) {
  11.             matched[v] = true;
  12.             mt[nxt] = v;
  13.             return true;
  14.         }
  15.     }
  16.    
  17.     for (int nxt : g[v]) {
  18.         if (Inc(mt[nxt])) {
  19.             matched[v] = true;
  20.             mt[nxt] = v;
  21.             return true;
  22.         }
  23.     }
  24.     return false;
  25. }
  26.  
  27. void BuildMT() {
  28.     memset(matched, 0, sizeof matched);
  29.     fill(mt, mt + MSIZE, -1);
  30.     for (int run = 1; run; ) {
  31.         run = 0;
  32.         memset(used, 0, sizeof used);
  33.         for (int i = 0; i < MSIZE; i++) {
  34.             if (!matched[i] && Inc(i)) {
  35.                 run = 1;
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement