1106 dfs

ph
이동: 둘러보기, 검색

(bipartite graph에서) dfs는 처음 보는데 참 보면 볼수록 오묘하고 이해가 안간다. 정말 오묘하고 신기하다.

bool dfs(int a)
{
	if (visited[a])
		return false;

	visited[a] = true;

	for (int b = 0; b < m; b++)
	{
		if (adj[a][b])
		{
			if (bMatch[b] == -1 || dfs(bMatch[b]))
			{
				aMatch[a] = b;
				bMatch[b] = a;

				return true;
			}
		}
	}

	return false;
}