Group A n person B group M person//MAX How many people match each person just once # include<stdio.h># include<string.h># include<algorithm>using namespace Std;int n,m,k;int pp[1100][1100],map[1100],vis[1100];int bfs (int x)//dichotomy matching template {for (int i=1;i<=m;i++)// People in Group B to cater for match {if (!vis[i]&&pp[x][i]) {vis[i]=1;if (!map[i]| | BFS (Map[i]))//b I have not matched or matched the number in Group A (Map[i]) can also find other people to match {Map[i]=x;return 1;}} return 0;} int main () {int count,i,a,b,c;while (~scanf ("%d", &n), N) {memset (pp,0,sizeof (PP)),//Match memset (map,0,sizeof (map) ); scanf ("%d%d", &m,&k); for (i=0;i<k;i++) {scanf ("%d%d%d", &a,&b,&c) ; Pp[b][c]=1;} count=0;//matches the number of people in the for (i=1;i<=n;i++)//a group to match {memset (vis,0,sizeof (VIS)), if (BFS (i)) count++;} printf ("%d\n", count);} return 0;}
HDU 1150 Machine Schedule (classic binary match)