标签:des style blog http color os io java strong
6 3 3 1 1 1 2 1 3 2 1 2 3 3 1 0
3
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MX=510;
int nv,nan;
bool g[MX][MX];//邻接矩阵
int link[MX];//link[y]表示当前与y节点相邻的x节点
bool pd[MX];//辅助数组
bool work(int x)
{
for(int i=1;i<=nan;i++)//枚举男生
{
if(g[x][i]&&!pd[i])//该男生是她想的人,且没有跟别人在一起
{
pd[i]=true;//在一起标记
if(link[i]==-1||work(link[i]))//如果该男生没有找对象,或者跟男生在一起的女生可以换个对象
{
link[i]=x;
return true;
}
}
}
return false;
}
int main()
{
int m;
while(scanf("%d",&m)!=EOF)
{
if(m==0)break;
scanf("%d%d",&nv,&nan);
int a,b,i,j,k,ans=0;
memset(g,0,sizeof g);
memset(link,-1,sizeof link);
for(i=0;i<m;i++)
{
scanf("%d%d",&a,&b);
g[a][b]=true;
}
for(i=1;i<=nv;i++)//枚举女生
{
memset(pd,0,sizeof pd);
if(work(i))//如果可以匹配
{
ans++;
}
}
printf("%d\n",ans);
}
return 0 ;
}
标签:des style blog http color os io java strong
原文地址:http://blog.csdn.net/fljssj/article/details/38930349