UVA - 11396 Claw Decomposition(二分图染色)
2017-07-17 18:29
281 查看
题目大意:给你一张无向图,每一个点的度数都是3。
你的任务是推断是否能把它分解成若干个爪(每条边仅仅能属于一个爪)
解题思路:二分图染色裸题。能够得出:爪的中心点和旁边的三个点的颜色是不一样的
你的任务是推断是否能把它分解成若干个爪(每条边仅仅能属于一个爪)
解题思路:二分图染色裸题。能够得出:爪的中心点和旁边的三个点的颜色是不一样的
#include <cstdio> #include <cstring> using namespace std; #define N 310 #define M 2010 struct Edge{ int to, Next; }E[M]; int head , color , tot; int n, m; void AddEdge(int from, int to) { E[tot].to = to; E[tot].Next = head[from]; head[from] = tot++; } void init() { memset(head, -1, sizeof(head)); tot = 0; int u, v; while (scanf("%d%d", &u, &v) && u + v) { AddEdge(u, v); AddEdge(v, u); } } bool bipartite(int u) { for (int i = head[u]; i != -1; i = E[i].Next) { int v = E[i].to; if (color[v] == color[u]) return false; if (!color[v]) { color[v] = 3 - color[u]; if (!bipartite(v)) return false; } } return true; } void solve() { memset(color, 0, sizeof(color)); color[1] = 1; if (bipartite(1)) printf("YES\n"); else printf("NO\n"); } int main() { while (scanf("%d", &n) != EOF && n) { init(); solve(); } return 0; }
相关文章推荐
- UVa 11396 - Claw Decomposition(二分图判定,染色法,dfs)
- UVA - 11396 Claw Decomposition(二分图染色)
- UVa - 11396 Claw Decomposition 二分图的判定
- uva 11396 Claw Decomposition(二分图判定 BFS)
- UVA-11396 Claw Decomposition (二分图判定)
- Uva 11396 Claw Decomposition __二分图判定__C__
- UVA 11396 Claw Decomposition(二分图)
- UVA 11396 Claw Decomposition 染色
- uva 11396 - Claw Decomposition(二分图判定)
- UVA 11396 Claw Decomposition(二分图判断)
- UVA 11396 - Claw Decomposition(二分图判定)
- uva 11396 - Claw Decomposition(二分图判定)
- UVA11396-Claw Decomposition(二分图判定)
- UVA 11396:Claw Decomposition(二分图判定)
- UVa-11396 Claw Decomposition(二分图判断)
- uva 11396 Claw Decomposition 二分图判定
- Uva 11396 Claw Decomposition(二分图判断)
- UVA-11396 - Claw Decomposition(DFS)
- UVA11396 Claw Decomposition
- UVa11396 - Claw Decomposition