二分匹配模板

bool dfs(int u)
{
	for(int i = 0; i < n; i++)
	{
		if(!used[i] && maz[u][i])
		{
			used[i] = true;
			if(match[i] == -1 || dfs(match[i]))
			{
				match[i] = u;
				return true;
			}
		}
	}
	return false;
}
int bipartite()
{
	int res = 0;
	memset(match, -1, sizeof(match));
	for(v = 0; v < n; v++)
	{
		memset(used, 0, sizeof(used));
		if(dfs(v))
			res++;
	}
	return res;
}

猜你喜欢

转载自blog.csdn.net/u013780740/article/details/38270627