int tol,head[maxn];
struct edge
{
int to,next;
}es[maxm];
void addedge( int u , int v )
{
es[tol].to = v;
es[tol].next = head[u];
head[u] = tol++;
}
int linker[maxn],un; bool used[maxn];
bool dfs( int u )
{
for ( int i=head[u] ; i!=-1 ; i=es[i].next )
{
int v = es[i].to;
if ( !used[v] )
{
used[v] = true;
if ( linker[v]==-1||dfs( linker[v] ) )
{
linker[v] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int res = 0;
memset ( linker , -1 , sizeof(linker) );
for ( int u=0 ; u<un ; u++ )
{
memset( used , false , sizeof(used) );
if ( dfs(u) ) res++;
}
return res;
}