题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1191
题解:
裸匈牙利,注意如果出现找不到增广路的情况就直接break
#include<cstdio>
#include<cstring>
#define MAXN 1010
int n,m,cnt,match[MAXN*],head[MAXN*],ans;
bool check[MAXN*];
struct node
{
int v,next;
}edge[MAXN*];
void add(int x,int y)
{
edge[++cnt].next=head[x];
head[x]=cnt;
edge[cnt].v=y;
}
bool Hungary(int u)
{
for(int i=head[u];i!=;i=edge[i].next)
{
int v=edge[i].v;
if(!check[v])
{
check[v]=true;
if(!match[v]||Hungary(match[v]))
{
match[v]=u;
return true;
}
}
}
return false;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
add(i,x+m+);
add(i,y+m+);
}
for(int i=;i<=m;i++)
{
memset(check,false,sizeof(check));
if(Hungary(i))ans++;
else break;
}
printf("%d\n",ans);
return ;
}