Http://www.cnblogs.com/pony1993/archive/2012/07/25/2607738.html
1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 Const intn=1001;7 intn1,n2,k;8 //N1,n2 is a set of vertices with a two-point graph, where x∈n1,y∈n29 intMap[n][n],vis[n],link[n];Ten //Link records the number of X points that match the point y in the N2 in N1 One A intFindintx) - { - inti; the for(i=1; i<=n2;i++) - { - if(Map[x][i]&&!vis[i])//X->i has edges, and node i is not searched - { +vis[i]=1;//tag node has been searched - //If I do not belong to the previous match m or I match to the node can find the augmented path + if(link[i]==0||find (Link[i])) A { atLink[i]=x;//Update - return 1;//Match Success - } - } - } - return 0; in } - intMain () to { + inti,x,y,s=0; -scanf"%d%d%d",&n1,&n2,&k); the for(i=0; i<k;i++) * { $scanf"%d%d",&x,&y);Panax Notoginsengmap[x][y]=1; - } the for(i=1; i<=n1;i++) + { Amemset (Vis,0,sizeof(Vis)); the if(Find (i)) +s++; - } $printf"%d\n", s); $ return 0; -}
View Code
"Algorithm Series learning" Hungarian algorithm