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.

题目大意用两种颜色给点涂色,任意相邻两点的颜色不能相同。

#include<stdio.h>
#include<memory.h>int edge[201][201];
int node[201];
int flag; //0 没相同的  1 表示有相同的 void DFS(int n,int begin,int color){       //n 点数  begin 当前遍历点  color 上一个点的涂抹颜色 1 2 color=(node[begin]==2?1:2);         int i;for(i=0;i<n;i++){if(edge[begin][i]){if(!node[i]){node[i]=color;DFS(n,i,color);}else if(node[i]==node[begin]){flag = 1;return ;}}}
}int main(){int n;  //节点数 while( ~scanf("%d",&n) && n ){int i,l; scanf("%d",&l);        //边数memset(edge,0,sizeof(edge));memset(node,0,sizeof(node));int x,y;for(i=0; i<l ; i++){scanf("%d%d",&x,&y);edge[x][y]=1;edge[y][x]=1;}flag = 0;node[x] = 1;DFS(n,x,1);if(!flag)printf("BICOLORABLE.\n");elseprintf("NOT BICOLORABLE.\n");      }return 0;
} 

10004 - Bicoloring相关推荐

  1. UVA 10004 - Bicoloring

    模拟染色,因为只有两种颜色,所以分别用 0. 1 代表这两种颜色,然后从0开始深搜,如果 每个点都能染上色,且相邻两点的颜色不同,则符合要求. #include<stdio.h>#incl ...

  2. UVA 10004 Bicoloring

    UVA_10004 对于这个题目,我们可以直接模拟染色的过程即可,如果发现要涂某一块时这个块已经被涂了色,并且与我们要使用的颜色不同的话,就说明这个图不能被染成BICOLORABLE的. #inclu ...

  3. UVA 10004 Bicoloring (二分染色)

    题目链接:https://vjudge.net/problem/UVA-10004 题意:给你一个连通图,问能否将每个节点染成两种颜色之一,使得每条边两边的节点颜色不同. (本质就是二分图的判定,有个 ...

  4. π-Algorithmist分类题目(2)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(2) Set Theory U ...

  5. (Step1-500题)UVaOJ+算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  6. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  7. 算法竞赛入门经典+挑战编程+USACO

    下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinej ...

  8. sicily题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  9. [sicily]部分题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

最新文章

  1. 安卓蓝牙键盘按键映射_双层按键功能自定义:魔蛋68蓝牙双模机械键盘体验
  2. 消息扩散(强连通分量)
  3. 006_JSONObject对象公共方法
  4. linux查询关键词上下行_Linux:从文件中搜索关键字并显示行数(cat,grep函数)
  5. JRebel : java.lang.OutOfMemoryError: PermGen space 异常
  6. 世界上最遥远的距离(泰戈尔)
  7. 【转】ABP源码分析三十六:ABP.Web.Api
  8. 计算机专业 程序员技术练级攻略(转载)
  9. Flask 上下文源码解析
  10. 基于递归寻找数组中的最大数字
  11. webview加载百度失败_移动AI系列百度paddle.js在助力开发智能化的微信小程序
  12. html5系列:notification api升级——从webkitNotifications到Notification
  13. 团队展示——我说的都队
  14. 计算机桌面保护时间,电脑处于屏幕保护或者休眠状态的时间怎么自己设置?
  15. 上一页 1 2 3 ... 10 下一页 固定分页
  16. 【新知实验室】关于实时音视频
  17. Elastic Stack之Beats(Filebeat、Metricbeat)、Kibana、Logstash教程
  18. Tkinter写一个音乐下载器
  19. python爬虫: 爬取拉勾网职位并分析
  20. 中金财富后台开发一面经验分享

热门文章

  1. Could not find artifact com.oracle:ojdbc6:pom:11.2.0.3 in central
  2. 不愧是阿里P8!深入理解Java虚拟机pdf百度云
  3. Linux-重命名命令rename
  4. 十本Android开发学习书籍下载链接
  5. python秒表游戏_如何使用Python 实现秒表功能?
  6. 毛星云opencv--多通道图像混合官方源码
  7. 读取excel中的表格数据到字典dict中--python
  8. 免费高清视频素材下载网站
  9. 【数学】手写开根号(牛顿迭代法 | 二分)
  10. linux下文件对比工具详解(diff、diff3、sdiff、vimdiff和comm)