The maximum match of the binary graph. The course and time can be seen as a binary chart.
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const intmaxn=505;intNx,ny;intG[MAXN][MAXN];intCX[MAXN],CY[MAXN];intMK[MAXN];intN;intzh[10000];intPathintu) { for(intv=0; v<ny; v++) { if(g[u][v]&&!Mk[v]) {Mk[v]=1; if(cy[v]==-1||path (Cy[v])) {Cx[u]=v; CY[V]=u; return 1; } } } return 0;}intMaxmatch () {intres=0; memset (CX,-1,sizeof(CX)); memset (CY,-1,sizeof(CY)); for(intI=0; i<nx; i++) { if(cx[i]==-1) {memset (MK,0,sizeof(MK)); Res=res+path (i); } } returnRes;}intMain () {inti,t,p,q; while(~SCANF ("%d",&NX)) {memset (g,0,sizeof(g)); for(i=0;i<10000; i++) zh[i]=-1; NY=0; for(i=0; i<nx;i++) {scanf ("%d",&t); while(t--) {scanf ("%d%d",&p,&q); if(zh[p* -+q]==-1) {zh[p* -+q]=NY; NY++; } g[i][zh[p* -+q]]=1; }} printf ("%d\n", Maxmatch ()); } return 0;}
POJ 2239 Selecting Courses