In 1976 the “Four Color Map Theorem” was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored using the same color as a neighbor region.

Here you are asked to solve a simpler similar problem. You have to decide whether a given arbitrary connected graph can be bicolored. That is, if one can assign colors (from a palette of two) to the nodes in such a way that no two adjacent nodes have the same color. To simplify the problem you can assume:

• no node will have an edge to itself.

• the graph is nondirected. That is, if a node a is said to be connected to a node b, then you must assume that b is connected to a.

• the graph will be strongly connected. That is, there will be at least one path from any node to any other node.

Input

The input consists of several test cases. Each test case starts with a line containing the number n (1 < n < 200) of different nodes. The second line contains the number of edges l. After this, l lines will follow, each containing two numbers that specify an edge between the two nodes that they represent. A node in the graph will be labeled using a number a (0 ≤ a < n).

An input with n = 0 will mark the end of the input and is not to be processed.

Output

You have to decide whether the input graph can be bicolored or not, and print it as shown below.

Sample Input

3

3

0 1

1 2

2 0

3

2

0 1

1 2

9

8

0 1

0 2

0 3

0 4

0 5

0 6

0 7

0 8

0

Sample Output

NOT BICOLORABLE.

BICOLORABLE.

BICOLORABLE.

问题链接:UVA10004 Bicoloring

问题简述:(略)

问题分析

这是一个典型的深度优先搜索问题。

程序说明

节点规模不大,图就用邻接矩阵来表示。

节点用两个颜色来图色,那就用0和1,程序15行实现了这个逻辑。

题记:(略)

参考链接:(略)

AC的C++语言程序如下:

/* UVA10004 Bicoloring */#include <bits/stdc++.h>using namespace std;const int N = 200;
int n, l, g[N][N], vis[N];bool dfs(int s)
{for (int i = 0; i < n; i++) {if (g[s][i]) {if (!vis[i]) {vis[i] = 1 - vis[s];if (!dfs(i))return false;} else if (vis[i] == vis[s])return false;}}return true;
}int main()
{while(~scanf("%d", &n) && n) {memset(g, 0, sizeof(g));memset(vis, 0, sizeof(vis));scanf("%d", &l);while(l--) {int source, target;scanf("%d%d", &source, &target);g[source][target] = g[target][source] = 1;}vis[0] = 1;printf("%s\n", dfs(0) ? "BICOLORABLE." : "NOT BICOLORABLE.");}return 0;
}

UVA10004 Bicoloring【DFS】相关推荐

  1. Bailian2815 城堡问题【DFS】

    2815:城堡问题 总时间限制: 1000ms 内存限制: 65536kB 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | ...

  2. Bailian2816 红与黑【DFS】

    2816:红与黑 总时间限制: 1000ms 内存限制: 65536kB 描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动.请写一 ...

  3. NUC1158 Lake Counting【DFS】

    Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...

  4. NUC1399 Sum It Up【DFS】

    Sum It Up 时间限制: 1000ms 内存限制: 65535KB 通过次数: 1总提交次数: 1 问题描述 Given a specified total t and a list of n ...

  5. HDU1181 变形课【DFS】(废除)

    新题解参见:HDU1181 变形课[DFS+关系闭包+bitset] 变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13107 ...

  6. 【DFS】巧妙取量的倒油问题

    题目描述 [题目描述]  有三个容器,容量分别为 a,b,c(a> b > c ),一开始a装满油,现在问是否只靠abc三个容器量出k升油.如果能就输出"yes",并且 ...

  7. [kuangbin]专题三 Dancing Links Squiggly Sudoku HDU - 4069【DFS】【精确覆盖】

    [题目描述] Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each ...

  8. 【DFS】不撞南墙不回头—深度优先搜索算法[Deep First Search]

    今天上午听到,那个非常6+1的李咏先生因癌症去世 DFS算法的基本模型 深度下,不撞南墙不回头,就是一直往后找,知道没有路了,向后返回. 想起一首民谣,<可能否>--木小雅 https:/ ...

  9. NUC1333 Knight Moves【DFS】

    Knight Moves 时间限制: 1000ms 内存限制: 65535KB 问题描述 A friend of you is doing research on the Traveling Knig ...

最新文章

  1. 你用过这种奇葩的C#注释吗?如何看待
  2. 【Android 逆向】ptrace 函数 ( C 标准库 ptrace 函数简介 | ptrace 函数真实作用 )
  3. android 手机关机代码非root,怎么用代码判断android手机是否开启了ROOT 权限知道...
  4. 程序员:你见过哪些要命的奇葩代码?
  5. ssh登陆connection refused的解决办法
  6. 【MapBox】5种地图(底图)样式自由切换附源码
  7. 如何在10分钟内让Redux发挥作用
  8. 10000个科学难题书籍介绍
  9. oracle默认的优化器,Oracle优化器相关参数设置
  10. 2018软工实践第五次作业——结对作业2
  11. Ubuntu系统下go语言环境的搭建
  12. 妲己机器人功能_来自机器人影响者的5个功能强大的Instagram教训
  13. 算法导论第三版第二章答案
  14. 【代码】eclipse搭建ssm框架所需约束
  15. Oracle Coherence 3.5 读书笔记之3 - 满足性能,可扩展和可用性目标
  16. ubutnu18+cuda11.1+cudnn8.0.4+nvidia-driver-465
  17. RNA m6A修饰问题汇总(第二期)
  18. 单片机读取EEPROM(AT24C64)值为0xff问题解决方法
  19. 浏览器创建render 树_如何为浏览器创建出色的游戏
  20. Ubuntu18.4设置永久DNS

热门文章

  1. WebSocket之JS发送二进制
  2. 资深开发者告诉你“页游转手游”应注意的五大点
  3. Android中RelativeLayout及TableLayout使用说明
  4. Hive中类SQL语言中的where 与having
  5. MySQL数据库导入SQL[ERR]Unknown collation: ‘utf8mb4_0900_ai_ci‘的解决办法
  6. android ui新控件,android_常用UI控件_01_TextView3_点击打开新的activity
  7. php curl修改ip,php中curl设置ip的方法
  8. C++ lambda表达式 std::function 深层详解
  9. 判定2022年是否闰年c语言_闰年的来历
  10. tensorflow精进之路(二十八)——人脸识别(下)(MTCNN人脸检查和人脸对齐+CASIA-WebFace数据集模型)