acm.hdu.edu.cn/showproblem.php?pid=2063
二分图最大匹配
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int V = 510;
const int E = 1010;
int k,n,m,G[V][V];
int check[V],ma[V],mb[V];
int DFS(int u){
for(int i=1; i<=m; i++){
if(!check[i] && G[u][i] > 0){
check[i] = 1;
if(mb[i] == -1 || DFS(mb[i])){
ma[u] = i;
mb[i] = u;
return 1;
}
}
}
return 0;
}
void MMC(){
int res = 0;
memset(mb, -1, sizeof(mb));
memset(ma, -1, sizeof(ma));
for(int i=1; i<=n; i++){
memset(check, 0, sizeof(check));
res += DFS(i);
}
printf("%d\n",res);
}
int main(){
while(scanf("%d%d%d",&k,&n,&m) == 3){
if(!k) break;
memset(G, 0, sizeof(G));
for(int i=0; i<k; i++){
int a,b;
scanf("%d%d",&a,&b);
G[a][b] = 1;
}
MMC();
}
return 0;
}