题目大意:给出一个简单无向图,每一个点的度为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. asp.net 下载任意格式文件 上传文件后台代码

    思路:将文件转化为流,输出到页面上的iframe中去 //下载附件逻辑 object DownLoad(NameValueCollection nv) { int attachId = nv[&quo ...

  2. STM32学习笔记2-系统时钟知识及程序配置

    一:基本知识 1.  STM32F103ZE有5个时钟源:HSI.HSE.LSI.LSE.PLL.   ①.HSI是快速内部时钟,RC振荡器,频率为8MHz,精度不高.   ②.HSE是快速外部时钟, ...

  3. How to get the source code of the chromium of the specified revision

    I'd like to get the source code of the chromium 34.0.1847.9. gclient config http://src.chromium.org/ ...

  4. [Android学习笔记]EditText的使用

    EditText就是我们最常用的文本输入框 常用属性见官方文档 主要是以下几个问题: 1.取消默认获取焦点 Activity启动时候会把焦点默认停留在第一个EditText控件上 一般的解决方法是在此 ...

  5. SWT可视化设计

    SWT可视化设计,可以使用Google的WindowBuilder. 在Google Code中,搜索WindowBuilder就可以看到路径. 在Eclipse中   Help--->Inst ...

  6. phing用户手册第四章Getting Started译文

    本章是phing的入门篇,查看 原文请猛击这里. XML And Phing 一个合法的Phing构建文件有以下几部分构成: 1.文档序言 2.唯一的根元素<project> 3.一些Ph ...

  7. Codeforces Round #296 (Div. 2) A. Playing with Paper

    A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an o ...

  8. android app 架构设计02

    二:在开放的过程中,尽量把工具类,BaseActivity 放在指定的位置. DateFormat Bitmap Notification Shared Preference Environment ...

  9. 【Gapps】安装GooglePlay引发一系列问题

    再次感谢小海的支持,感谢大家的支持! 从安装CM至如今GooglePlay,小海为我提供了非常多方案,能够说是全面支持.仅仅是出于隐私不便公开他的个人信息,仅提供一个他的博客地址http://luha ...

  10. Android getTopActivity的方法

    使用例如以下方法能够获得top activity 的name public String getTopActivityPackageName(Context context) { String top ...