Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23984 Accepted Submission(s): 10453
1<=N 和M<=500.接下来的K行,每行有两个数,分别表示女生Ai愿意和男生Bj做partner。最后一个0结束输入。
#include <cstring> #include <cstdio> #define N 505 bool vis[N]; int ans,Map[N][N],match[N],k,m,n; int dfs(int x) { for(int i=1;i<=n;++i) { if(Map[x][i]&&!vis[i]) { vis[i]=1; if(!match[i]||dfs(match[i])) { match[i]=x; return 1; } } } return 0; } int main() { for(;scanf("%d",&k)&&k;) { scanf("%d%d",&m,&n); memset(Map,0,sizeof(Map)); memset(match,0,sizeof(match)); ans=0; for(int x,y;k--;) { scanf("%d%d",&x,&y); Map[x][y]=1; } for(int i=1;i<=m;++i) { memset(vis,0,sizeof(vis)); ans+=dfs(i); } printf("%d\n",ans); } return 0; }