二分图匹配
code:
/**************************************************************
Problem: 1191
Language: C++
Result: Accepted
Time:24 ms
Memory:1400 kb
****************************************************************/
// Forever_LF
#include<cstdio>
#include<cstring>
#include<iostream>
usingnamespace std;
structnode
{
intx,y,next;
}a[10000]; intlen,first[1100];
bool v[1100];
int belong[1100];
void ins( int x,inty )
{
len++;
a[len].x=x; a[len].y=y;
a[len].next = first[x]; first[x] = len;
}
bool ex( int x )
{
for(int k=first[x];k;k=a[k].next )
{
inty=a[k].y;
if( v[k] )continue;
v[k] =true;
if( !belong[y] || ex( belong[y] ) )
{
belong[y] = x;
returntrue;
}
}
returnfalse;
}
int main()
{
memset( belong,0,sizeofbelong );
inti,j,n,m,k,l,o;
scanf("%d%d",&n,&m);
for( i=1;i<=m;i++ )
{
scanf("%d%d",&k,&l);
ins( i,k );
ins( i,l );
}
for( i=1;i<=n;i++ )
{
memset( v,false,sizeofv );
if( !ex(i) )break;
}
printf("%d\n",i-1);
return0;
}