HDU 2063 过山车
简单的最大二分图匹配
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 #include<cstdio> 5 #include<cstring> 6 7 #define MAXN 505 8 9 int match[MAXN]; 10 int map[MAXN][MAXN]; 11 int vis[MAXN]; 12 int K,M,N; 13 14 int find(int x) 15 { 16 for(int i=1;i<=N;i++) 17 { 18 if(map[x][i]&&!vis[i]) 19 { 20 vis[i] = 1; 21 if(!match[i] || find(match[i])) 22 { 23 match[i] = x; 24 return 1; 25 } 26 } 27 } 28 return 0; 29 } 30 31 int main() 32 { 33 while(scanf("%d",&K)!=EOF,K) 34 { 35 scanf("%d%d",&M,&N); 36 memset(map,0,sizeof(map)); 37 memset(match,0,sizeof(match)); 38 int a,b; 39 for(int i=0;i<K;i++) 40 { 41 scanf("%d%d",&a,&b); 42 map[a][b]=1; 43 } 44 45 int ans=0; 46 for(int i=1;i<=M;i++) 47 { 48 memset(vis,0,sizeof(vis)); 49 ans+=find(i); 50 } 51 printf("%d\n",ans); 52 } 53 return 0; 54 }