标签:二分 title std lib cep 练习 ++ 最大匹配 组合
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23977 Accepted Submission(s): 10449
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 1500+10 using namespace std; bool vis[N]; int n,m,k,x,y,girl[N],map[N][N]; int read() { int x=0,f=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} return x*f; } int find(int x) { for(int i=1;i<=m;i++) { if(!vis[i]&&map[x][i]) { vis[i]=true; if(girl[i]==-1||find(girl[i])) {girl[i]=x;return 1;} } } return 0; } int main() { int t=0,sum,ans; while(1) { k=read();if(k==0) break; n=read(),m=read(),ans=0; memset(map,0,sizeof(map)); for(int i=1;i<=k;i++) x=read(),y=read(),map[x][y]=1; memset(girl,-1,sizeof(girl)); for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(find(i)) ans++; } printf("%d\n",ans); } return 0; }
标签:二分 title std lib cep 练习 ++ 最大匹配 组合
原文地址:http://www.cnblogs.com/z360/p/7434496.html