bzoj1191[HNOI2006]超级英雄Hero

裸的二分图匹配,毕竟是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[N][N],l[N];
bool y[N];
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;
}


你可能感兴趣的:(二分图匹配)