#include <iostream>#include<cstdio>#include<cstring>#include<queue>#defineMem (A, B) memset (A,b,sizeof (a))using namespacestd;Const intMAXN = -, INF =0xFFFFFFF;intCX[MAXN], CY[MAXN], DX[MAXN], DY[MAXN], USED[MAXN], G[MAXN][MAXN];intNX, NY, DIS;intBFs () {Queue<int>Q; Dis=INF; Mem (DX,-1); Mem (DY,-1); for(intI=1; i<=nx; i++) { if(Cx[i] = =-1) {Q.push (i); Dx[i]=0; } } while(!Q.empty ()) { intU =Q.front (); Q.pop (); if(Dx[u] > Dis) Break; for(intI=1; i<=ny; i++) { if(G[u][i] && dy[i] = =-1) {Dy[i]= Dx[u] +1; if(Cy[i] = =-1) dis =Dy[i]; Else{Dx[cy[i]]= Dy[i] +1; Q.push (Cy[i]); } } } } returnDis! =INF;}intDfsintu) { for(intI=1; i<=ny; i++) { if(G[u][i] &&!used[i] && dy[i] = Dx[u] +1) {Used[i]=1; if(Cy[i]! =-1&& dis = = Dy[i])Continue; if(Cy[i] = =-1||DFS (Cy[i])) {Cy[i]=u; Cx[u]=i; return 1; } } } return 0;}intHC () {intres =0; MEM (CX,-1); Mem (CY,-1); while(BFS ()) {mem (used,0); for(intI=1; i<=nx; i++) { if(Cx[i] = =-1&&DFS (i)) Res++; } } returnRes;}intMain () {return 0;}
Hopcroft-carp algorithm template for personal use