Facebook
From Commodious Bee, 7 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 231
  1. bool matching(int x, int p) {
  2.         visit[x] = true;
  3.  
  4.         for(int i = 0; i < (int)graf[x].size(); i++) {
  5.                 int y = graf[x][i];
  6.                                        
  7.                 if(y != p && (mate[y] == -1 || dfs(mate[y], y) == true)) {
  8.                         mate[x] = y;
  9.                         mate[y] = x;
  10.                         return true;
  11.                 }
  12.         }
  13.        
  14.         return false;
  15. }