int g[MAXN][MAXM],used[MAXM];
bool dfs(int u)
{
for(int i=1;i<=vN;i++)
{
if(!used[i] && g[u][i])
{
used[i] = true;
if(match[i] == -1 || dfs(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int ret = 0;
for(int i=1;i<=uN;i++)
{
memset(used,0,sizeof(used));
if(dfs(i)) ret++;
}
return ret;
<p>}</p><p>
</p>
<pre name="code" class="cpp">int match[MAXN];
bool used[MAXN];
vector<int>G[MAXN];
int uN;
bool dfs(int u)
{
for(int i=0;i<G[u].size();i++)
{
if(!used[G[u][i]])
{
used[G[u][i]]=true;
if(match[G[u][i]]==-1||dfs(match[G[u][i]]))
{
match[G[u][i]]=u;
return true;
}
}
}
return false;
}
int hungary()
{
int u;
int res=0;
memset(match,-1,sizeof(match));
for(u=0;u<uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
void addedge(int u,int v)
{
edge[tot].to = v;edge[tot].next = head[u];
head[u] = tot++;
}
bool dfs(int u)
{
for(int i = head[u]; i != -1;i = edge[i].next)
{
int v = edge[i].to;
if(!used[v])
{
used[v] = true;
if(match[v] == -1 || dfs(match[v]))
{
match[v] = u;
return true;
}
}
}
return false;
}
int hungary()
{
int res = 0;
memset(match,-1,sizeof(match));
for(int u = 0;u < uN;u++)
{
memset(used,false,sizeof(used));
if(dfs(u))res++;
}
return res;
}