【模板】二分图染色

C++版本:

二分图染色

bool dfs(int x, int u, int c) {
	color[u] = c;
	for (int i = head[u]; i; i = eg[i].nex) {
		if (eg[i].cost <= x)continue;
		int v = eg[i].to;
		if (color[v] == c)return false;
		if (color[v] == 0 && !dfs(x, v, -c))return false;
	}
	return true;
}
bool check(int x) {
	memset(color, 0, sizeof(color));
	for (int i = 1; i <= V; i++)
		if (color[i] == 0) {
			if (!dfs(x, i, 1))return false;
		}
	return true;
}
posted @ 2020-09-13 18:15  pjhui  阅读(101)  评论(0编辑  收藏  举报