[Notes] bipartite graph templates

Find online, wrote a very clear ah

 

#include <cstdio> 
#include <CString> 
#include <algorithm>
 the using  namespace STD;
 const  int N = 1005 ;
 BOOL Road [N] [N], Used [N];
 int match [N], n-, m, E ;
 / * 
definition of 
road [i] [j] == 1 represents the set of i left to the right side of the set j have 
used [i] == 1 is augmented at every time when the record has the right set of access node i 
record the right set of nodes that match [i] j of the matching object 
n, m, e as the title (left set size, the right set size, the number of edges) 
* / 
BOOL DFS ( int X) 
{ 
     for ( int i = . 1 ; i <= m; ++ I)
          IF ! (Used [I] && Road [X] [I])// determines whether this edge can go 
         {                      
             Used [I] = . 1 ; // record the node has been accessed prevent looping       
             IF (! Match [I] || DFS (match [I])) 
             { // If this point may be let out             
                 match [I] = X; 
                  return  true ; // record the new matching point returns true                  
             } 
         }     
     return  to false ; // match fails                                                   
}
 int main () { 
    Scanf ( " % D% D% D ", &n, &m, &e);
    for(int i = 1, x, y; i <= e; ++i)
    {
        scanf("%d%d", &x, &y);
        road[x][y] = 1;
    }
    int ans = 0;//答案                                               
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= m; ++j) used[j] = 0;//每次查询前都要清空used
        IF (DFS (I)) ANS ++;                        // if this point matching point can be found, then the answer to add a 
    } 
    the printf ( " % D " , ANS);
     return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/xwww666666/p/11832851.html