题目大意:给出一个简单无向图,每一个点的度为3。推断是否能将此图分解成若干爪的形式。使得每条边都仅仅出如今唯一的爪中。

(点能够多次出如今爪中)

这道题实质上就是问这个图是否为二分图,dfs判定就可以

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#define eps 1e-6
#define LL long long
using namespace std; const int maxn = 300 + 5;
const int INF = 0x3f3f3f3f;
vector<int> G[maxn];
//dfs给二分图进行黑白二着色,用颜色1表示黑色,颜色2表示白色,0表示没着色
int color[maxn]; //推断节点u所在的连通分量是否为二分图
int n;
bool bipartite(int u) {
for(int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if(color[v] == color[u]) return false;
if(!color[v]) {
color[v] = 3 - color[u];
if(!bipartite(v)) return false;
}
}
return true;
} void init() {
memset(color, 0, sizeof(color));
for(int i = 1; i <= n; i++) G[i].clear();
int x, y;
while(scanf("%d%d", &x, &y) == 2 && x) {
G[x].push_back(y);
G[y].push_back(x);
}
} void solve() {
color[1] = 1;
if(bipartite(1)) puts("YES");
else puts("NO");
} int main() {
//freopen("input.txt", "r", stdin);
while(scanf("%d", &n) == 1 && n) {
init();
solve();
}
return 0;
}

uva 11396Claw Decomposotion(二分图判定)的更多相关文章

  1. UVA 11080 - Place the Guards(二分图判定)

    UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...

  2. UVa 11396 爪分解(二分图判定)

    https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...

  3. poj2942 Knights of the Round Table,无向图点双联通,二分图判定

    点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...

  4. CF687A. NP-Hard Problem[二分图判定]

    A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. COJ 0578 4019二分图判定

    4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...

  6. hdoj 3478 Catch(二分图判定+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...

  7. HDU2444(KB10-B 二分图判定+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  8. DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)

    一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...

  9. HihoCoder 1121 二分图一•二分图判定

    二分图一•二分图判定 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 大家好,我是小Hi和小Ho的小伙伴Nettle,从这个星期开始由我来完成我们的Weekly. 新年回 ...

随机推荐

  1. niu人

    金步国简历 金步国简历 基本资料 姓名 金步国 性别 男 年龄 30 籍贯 江苏 淮安 院校 同济大学 专业 土木工程 学历 本科肄业 工作经验 5年 期望地点 长江以南 期望薪水 18000/月 个 ...

  2. C++不确定行为

    一个简单的程序引发了一块让人纠结的领域,也许强调编程规范的重要性也在这把.规范了就easy避免一些问题. 程序是这种 int Change(int& a) { a = 4; return a; ...

  3. [ACM] hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...

  4. RegisterHotKey注册热键,然后响应WM_HOTKEY消息

    MSDN中的一个示例代码,步骤就是RegisterHotKey注册热键,然后响应WM_HOTKEY消息 @1:这个是系统热键 #include "stdafx.h" int _cd ...

  5. Delphi对WM_NCHITTEST消息的处理

    前提:WM_NCHITTEST是很重要的,只要鼠标在活动,Windows无时无刻在发这个消息进行探测. ------------------------------------------------ ...

  6. TComponent明明实现了IDispatch接口,但是却不加上声明,难道是因为FVCLComObject实体对象不存在?

    TComponent明明实现了IDispatch接口,可是它的声明却是: TComponent = class(TPersistent, IInterface, IInterfaceComponent ...

  7. oracle存储过程、声明变量、for循环(转)

    oracle存储过程.声明变量.for循环 1.创建存储过程 create or replace procedure test(var_name_1 in type,var_name_2 out ty ...

  8. schedule()函数的调用时机(周期性调度)

    今天纠正了一个由来已久的认识错误:一个进程的时间片用完之后,当再次发生时钟中断时内核会调用schedule()来进行调度,把当前的进程上下文切出CPU,并把选定的下一个进程切换进来运行.我一直以为sc ...

  9. 2014 CSDN博文大赛终于获奖名单发布

    博文大赛第二阶段(2014年7月15日-2014年8月10日)已经结束,决赛获奖名单已在8月11日出炉. 现将获奖名单发布: 移动开发 NO.1    罗升阳    Luoshengyang    S ...

  10. 关于在ios7之后改变状态栏颜色

    看到网上都说 在ios7之后要这样设置 首先,须要在Info.plist配置文件里,添加键:UIViewControllerBasedStatusBarAppearance,并设置为YES: 然后,在 ...