1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <iostream> #include <stdio.h> #include <string.h>
using namespace std;
int girls[505];//存放男孩的匹配女孩 bool flag[505];//存放标记 bool relation[505][505];//存放关系 int k,m,n;
//第x个女孩找匹配对象 bool f(int x) { for(int j=1;j<=n;j++){ if(relation[x][j]&&!flag[j]){ flag[j]=1; if(girls[j]==0||f(girls[j])){ girls[j]=x; return true; } } } return false; }
int main() { while(scanf("%d",&k)!=EOF&&k!=0) { scanf("%d%d",&m,&n); int x,y; memset(relation,0,sizeof(relation)); memset(girls,0,sizeof(girls)); for(int i=0;i<k;i++){ cin>>x>>y; relation[x][y]=1; } int sum=0; for(int i=0;i<m;i++){ memset(flag,0,sizeof(flag)); if(f(i+1))sum++; } cout<<sum<<endl; } return 0; }
|