标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12125 Accepted Submission(s): 5302
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<string> using namespace std; int k,n,m,link[505],mark[505],g[505][505],boy,girl; bool dfs(int t) { for(int i=1;i<=m;i++) { if(g[t][i]&&mark[i]==-1) { mark[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=t; return true; } } } return false; } int main() { while(scanf("%d%d%d",&k,&n,&m)!=EOF) { if(k==0) break; int ans=0; memset(link,-1,sizeof(link)); memset(g,0,sizeof(g)); for(int i=1;i<=k;i++) { scanf("%d%d",&girl,&boy); g[girl][boy]=1; } for(int i=1;i<=n;i++) { memset(mark,-1,sizeof(mark)); if(dfs(i)) ans++; } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4248647.html