标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15107 Accepted Submission(s): 6623
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<algorithm> #define mem(x,y) memset(x,y,sizeof(x)) using namespace std; const int INF=0x3f3f3f3f; const int MAXN=1010; int mp[MAXN][MAXN]; int vis[MAXN],usd[MAXN]; int n,m; bool dfs(int x){ for(int i=1;i<=n;i++){//第二个是男孩 if(!vis[i]&&mp[x][i]){//注意 vis[i]=1; if(usd[i]==-1||dfs(usd[i])){ usd[i]=x; return true; } } } return false; } int main(){ int k,a,b; while(scanf("%d",&k),k){ scanf("%d%d",&m,&n); mem(mp,0); while(k--){ scanf("%d%d",&a,&b); mp[a][b]=1; } mem(vis,0);mem(usd,-1); int ans=0; for(int i=1;i<=m;i++){//第一个是女孩的 mem(vis,0); if(dfs(i))ans++; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4957332.html