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. 第01章_数据库概述
  2. input常用输入框限制
  3. python文件读写小结
  4. c语言代码测试电脑性能,【图片】今天写几个性能测试,为什么C语言跑得这么慢呢??【c语言吧】_百度贴吧...
  5. linux 网卡no carrier,linux centos 7 网卡突然不能上网异常解决
  6. dorado 7 使用总结
  7. DeepMind成为AI界创业加速营:3年17名资深员工与高管离职
  8. Mysql 8.0 | #08004Client does not support authentication protocol requested by server
  9. 贪吃蛇代码--c语言版 visual c++6.0打开
  10. 旅游日记——2000元北京6天5夜游
  11. php root进程保存文件夹,thinkphp5日志文件夹及文件权限问题的解决
  12. Sentinel Slot扩展实践-流控熔断预警实现
  13. Gramine(原graphene-sgx)软件栈
  14. 7-6 分支结构——大小写字母判断 (15 分)
  15. 深信服2018年实习生校园招聘总结
  16. 数据安全与销毁:数据安全已经上升到了国家战略层面
  17. 【CICE-A7a】人身保险会计与财务(上)
  18. CMMI中所有的22个KPA(关键过程域)
  19. php 爬虫 超市,scrapy爬虫 爬取天猫进口零食网页
  20. 强大的UI组件集Telerik R3 2022支持.NET 7、全新的主题等

热门文章

  1. mysql gis vs postgis_mysql空间扩展VSPostGIS
  2. 阿里服务器降温系统,双十一服务器靠“泡澡”降温?阿里看上了3M的这项“冷”科技...
  3. Kylin之Caused by :...The table :DWD_ORDER_INFO Dup key found
  4. Phoenix的数据类型和操作符、函数
  5. java split 实现_PL/SQL实现JAVA中的split()方法的例子
  6. core api其他电脑不能访问接口_第 12 篇:加缓存为接口提速
  7. python中文单词_python – 如何显示中文单词,而不是unicode单词
  8. Abb变频器输参数只读_ABB变频器ACSM1-04/ACS380产品参数说明及功能介绍
  9. 对象 'dbo.xxx' 不存在,或对此操作无效。为表创建触发器,为什么提示对象不存在?
  10. php高强度精密涂覆钢管,电力内外涂覆钢管