UVA11396-Claw Decomposition(二分图判定)
题意:能否将一张无向连通图分解成多个爪型。每一条边仅仅能属于一个爪型,每一个点的度数为3.
思路:当图分解成类干个爪型时,每条边仅仅属于一个爪子,所以每条边的两个点一定要处于2个不同的鸡爪中
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> using namespace std; const int MAXN = 305; vector<int> g[MAXN];
int n, color[MAXN]; void init() {
for (int i = 0; i < n; i++)
g[i].clear();
} bool bipartite(int u) {
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][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() {
while (scanf("%d", &n) && n) {
init();
int u, v;
while (scanf("%d%d", &u, &v)) {
if (u == 0 && v == 0)
break;
u--;
v--;
g[u].push_back(v);
g[v].push_back(u);
} memset(color, 0, sizeof(color));
color[0] = 1;
if(bipartite(0))
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
UVA11396-Claw Decomposition(二分图判定)的更多相关文章
- UVA-11396 Claw Decomposition (二分图判定)
题目大意:给一张无向图,能否把它分成若干个“爪”,即,一个点有三个子节点. 题目分析:每个点的度数3是已知的,只需判断一下是不是二分图即可. 代码如下: # include<iostream&g ...
- UVa 11396 爪分解(二分图判定)
https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...
- 图论trainning-part-2 B. Claw Decomposition
B. Claw Decomposition Time Limit: 1000ms Memory Limit: 131072KB 64-bit integer IO format: %lld ...
- CF687A. NP-Hard Problem[二分图判定]
A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- COJ 0578 4019二分图判定
4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...
- hdoj 3478 Catch(二分图判定+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...
- UVA 11080 - Place the Guards(二分图判定)
UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...
- poj2942 Knights of the Round Table,无向图点双联通,二分图判定
点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...
- HDU2444(KB10-B 二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
随机推荐
- SESC中的热量模拟器
SESC安装见前文 配置sesc支持热量模拟 ../sesc/configure --enable-power --enable-therm make 遇到问题: 1 找不到 liblevmar.a ...
- Django写的投票系统1(转)
当然主要是从django的帮助文档里面来的,权当是翻译吧 这个投票系统的主要功能有 1.一个前台页面,可以让用户来投票 2.一个管理员页面,可以用来添加.修改.删除投票 首页第一步要确定你已经安装了D ...
- 单点更新线段树 RMQ
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- python基础课程_2学习笔记3:图形用户界面
图形用户界面 丰富的平台 写作Python GUI程序前,须要决定使用哪个GUI平台. 简单来说,平台是图形组件的一个特定集合.能够通过叫做GUI工具包的给定Python模块进行訪问. 工具包 描写叙 ...
- Knockout应用开发指南 第三章:绑定语法(1)
原文:Knockout应用开发指南 第三章:绑定语法(1) 第三章所有代码都需要启用KO的ko.applyBindings(viewModel);功能,才能使代码生效,为了节约篇幅,所有例子均省略了此 ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- Amazon AWS创建RHEL 7实例
在AWS上登录 如果没有账号的话先注册,参考 http://blog.banban.me/blog/2014/06/09/li-yong-awsmian-fei-zhang-hu-da-jian-vp ...
- Android自己定义控件系列一:Android怎样实现老版优酷client三级环形菜单
转载请附上本文链接:http://blog.csdn.net/cyp331203/article/details/40423727 先来看看效果: 一眼看上去好像还挺炫的,感觉比較复杂...实际上并不 ...
- firefox os 2.1版本号UI接口方面有了质的飞跃
由Mozilla新的移动设备操作系统开发Firefox os 经过多次迭代,我们看到的版本号Mozilla进步和艰辛,在充满当然,任何Android设备的情况下,坚持一个新的操作系统的移动设备,后1. ...
- 重新想象 Windows 8 Store Apps (2) - 控件之按钮控件: Button, HyperlinkButton, RepeatButton, ToggleButton, RadioButton, CheckBox, ToggleSwitch
原文:重新想象 Windows 8 Store Apps (2) - 控件之按钮控件: Button, HyperlinkButton, RepeatButton, ToggleButton, Rad ...