# Back to the classic-M graph coloring problem (difference from the map's four colors)

Source: Internet
Author: User

Four-color problem:

The four-color problem is a special feature of the M image coloring problem. According to the four-color principle, it is proved that all areas of any map on the plane or sphere can be colored in four colors at most, and make any two adjacent areas with a public boundary do not have the same color. This problem can be converted into a 4-color decision problem (PlanIs a graph that can be painted on a plane without any crossover on the side ). Change each area of the map to a node. If the two areas are adjacent, the corresponding node is connected with an edge. Although it has been proved that five colors are sufficient to color any map for many years, no map with more than four colors is found. It was not until 1976 that the problem had been solved by the help of computers by K. I. Apple, W. haken and J. Koch. They prove that four colors are sufficient to color any map.

In this section, we do not only consider those images produced by the map, but all the images. We discuss all the different ways to color a given graph when at most M colors are used.

Problem of M image coloring:

Question:

1. A graph G and M> 0 colors are known. When only these M colors are used to color the nodes of G, can the two adjacent nodes in the graph have different colors? This problem is calledM-coloring problem.

2.M-coloring OptimizationThe problem is to find the smallest integer m that can be colored on the graph G. This integer is called the graph G'sColor count. This is the minimum coloring problem of the graph, and the M value is obtained.

Solution:

The first problem is m-coloring:

The backtracking method can be used to continuously color each node. After the first n-1 nodes are properly colored, the nth node is colored, in this case, the available M colors are enumerated. The color of the node adjacent to the N node is used to determine whether the color is valid, if a color is found so that the nth node can be colored, it indicates that the M color scheme is feasible. Return to the truth:

// It is not feasible to determine whether the color is applied to the current node. It is used to determine the color of the adjacent node. The adjacent table is used to store the Graph Information. <br/> bool isok (INT step) <br/>{< br/> vector <int>: iterator ITER; <br/> for (iter = input [STEP]. begin (); iter! = Input [STEP]. end (); ITER ++) <br/>{< br/> If (color [STEP] = color [* ITER]) return false; <br/>}< br/> return true; <br/>}< br/> // step indicates 0-> N nodes, color_num indicates the number of colors available for color_num <br/> // determines whether the number of colors given to color_num is feasible. If it is feasible, true is returned, otherwise false <br/> bool DFS (INT step, int color_num) <br/>{< br/> If (Step> = N) return true; <br/> else <br/> {<br/> int I; <br/> for (I = 1; I <= color_num; I ++) <br/>{< br/> color [STEP] = I; <br/> If (isok (STEP )) <br/>{< br/> If (DFS (Step + 1, color_num) <br/> return true; <br/>}< br/> color [STEP] = 0; <br/>}< br/> return false; <br/>}

The second problem: Find the minimum number of colors m

With the accumulation of the above problems, it is very easy to solve this problem. As long as the number of colors from 1 to n is enumerated, the above DFS (0, m) is called ), if true is returned for one call, the color is the minimum required color.

For (I = 1; I <= N; I ++) <br/> {<br/> If (DFS (0, I )) <br/>{ <br/> cout <"the min colors:" <I <Endl; <br/> break; <br/>}< br/>}

Refer:

Http://www.cppblog.com/3522021224/archive/2007/06/26/27021.html

Http://blog.csdn.net/normalnotebook/archive/2006/06/25/832732.aspx

Http://blog.csdn.net/fableboy/archive/2009/03/08/3969452.aspx

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.