The questions are as follows:
In 1976 the ''four color map theorem "was proven with the balance of acomputer. this theorem states that every map can be colored using only fourcolors, in such a way that no region is colored using the same color as aneighbor region.
Here you are asked to solve a simpler similar problem. youhave 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 sucha way that no two adjacent nodes have the same color. to simplify the problemyou can assume:
- No node will have an edge to itself.
- The graph is nondirected. That is, if a nodeAIs said to be connectedto a nodeB, Then you must assume thatBIs connectedA.
- The graph will be strongly CTED. That is, there will be at leastone path from any node to any other node.
Input the input consists of several test cases. Each test casestarts with a line containing the number
N(1 <
N<200) of differentnodes. The second line contains the number of Edges
L. After this,
LLineswill follow, each containing two numbers that specify an edge between the twonodes that they represent. A node in the graph will be labeled using a number
A().
An inputN= 0 will mark the end of the input and isnot to be processed.
Output you have to decide whether the input graph can bebicolored or not, and print it as shown below. sample input
330 11 22 0980 10 20 30 40 50 60 70 80
Sample output
NOT BICOLORABLE.BICOLORABLE.
Ask if two colors can be used to dye a undirected strong connected graph. In fact, this graph can be converted to a bipartite graph. The necessary and sufficient condition for a bipartite graph is that every circle in the graph is an even number. Therefore, use DFS to find the length of each circle in the graph and then determine whether it is an even number, it is worth noting that the VIS mark array should not mark nodes, because nodes may be accessed multiple times, but the edge should be marked for the two-dimensional array. During the circle searching process, the edge cannot be traversed repeatedly, 1A.
The AC code is as follows: