二分图最大匹配
struct node{ int s,t,nxt ; }e[1005] ; int k,m,n,head[505],cnt,match[505],vis[505] ; int find(int s) { for(int i=head[s] ;i!=-1 ;i=e[i].nxt) { int tt=e[i].t ; if(!vis[tt]) { vis[tt]=1 ; if(match[tt]==-1 || find(match[tt])) { match[tt]=s ; return 1 ; } } } return 0 ; } int max_match() { int ans=0 ; memset(match,-1,sizeof(match)) ; for(int i=1 ;i<=m ;i++) { memset(vis,0,sizeof(vis)) ; ans+=find(i); } return ans; } void add(int s,int t) {e[cnt].s=s ;e[cnt].t=t ;e[cnt].nxt=head[s] ;head[s]=cnt++ ;} void read_graph() { memset(head,-1,sizeof(head)) ; cnt=0 ; for(int i=0 ;i<k ;i++) { int s,t ; scanf("%d%d",&s,&t) ; add(s,t) ; } }
原文:http://www.cnblogs.com/xiaohongmao/p/3653686.html