【模板】二分图染色
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;
}