您的位置:首页 > 其它

bzoj1191[HNOI2006]超级英雄Hero

2015-12-12 11:48 288 查看
裸的二分图匹配,毕竟是t1,但是主要是有一句题目一旦没办法匹配了就要break,没看到闯关制的我调了好久

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
inline LL read()
{
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
#define N 1005
int a

,l
;
bool y
;
int n,m;

bool match(int x)
{
fo(i,0,n-1)
if (y[i]==0&&a[x][i])
{
y[i]=1;
if (l[i]==0||match(l[i]))
{
l[i]=x;
return 1;
}
}
return 0;
}

int main()
{
memset(l,0,sizeof(l));
n=read(),m=read();
fo(i,1,m)
{
int x=read(),y=read();
a[i][y]=1;
a[i][x]=1;
}

int ans=0;
fo(i,1,m)
{
memset(y,0,sizeof(y));
if (match(i)) ans++;
else break;
}
printf("%d\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  二分图匹配