UVa 10004 - Bicoloring
2013-09-16 13:45
375 查看
题目大意:二着色问题:给你一个图,给图中的所有点染色,只有两种颜色可选,使得每条边的两个顶点的颜色不同。二分判定问题,可用DFS或BFS解决。
View Code
#include <cstdio> #include <cstring> #define MAXN 210 bool G[MAXN][MAXN]; int n, color[MAXN]; bool bipartite(int u) { for (int i = 0; i < n; i++) if (G[u][i]) { int v = i; if (color[u] == color[v]) return false; if (!color[v]) { color[v] = 3 - color[u]; if (!bipartite(v)) return false; } } return true; } int main() { #ifdef LOCAL freopen("in", "r", stdin); #endif while (scanf("%d", &n) && n) { int k; scanf("%d", &k); int x, y; memset(G, 0, sizeof G); for (int i = 0; i < k; i++) { scanf("%d%d", &x, &y); G[x][y] = G[y][x] = 1; } memset(color, 0, sizeof color); color[0] = 1; if (bipartite(0)) printf("BICOLORABLE.\n"); else printf("NOT BICOLORABLE.\n"); } return 0; }
View Code
相关文章推荐
- uva10004 Bicoloring 二分图染色
- UVA - 10004 Bicoloring (dfs和bfs两种解法)
- uva10004 Bicoloring 黑白染色问题,DFS
- uva 10004 - Bicoloring
- uva 10004 Bicoloring(二染色)
- UVA 10004 Bicoloring
- UVA 10004 Bicoloring
- uva10004 Bicoloring 黑白染色问题,DFS
- UVA 10004 Bicoloring
- UVA - 10004 Bicoloring(判断二分图——交叉染色法 / 带权并查集)
- UVA 10004 - Bicoloring(DFS)
- UVA - 10004 Bicoloring
- UVA 10004 - Bicoloring
- UVA 10004 Bicoloring
- UVA - 10004 Bicoloring
- UVa 10004 Bicoloring(二分图判定+DFS)
- UVa 10004 Bicoloring
- UVa 10004 Bicoloring (DFS&二分图)
- uva 10004 Bicoloring (二分图染色/求一个二分图)
- UVa 10004 - Bicoloring