Algorithm Design Example: m coloring (backtracking) memory limit: 2000 kb time limit: MSaccept: 8 submit: 14 Description given undirected connected graph G and m different colors. These colors are used to color the vertices of graph G. Each vertex has a color. Whether there is a coloring method to make the two vertices of each edge in G different colors. How many methods can be used to color the graph m. The first Input is the number of test samples T (T <120), followed by T test samples. The first line of each test sample is vertex number n, Edge Number M, and available color number m (n <= 10, M <100, m <= 7 ), in the next M row, each row has two integers u and v, indicating that the vertex u and v are connected by an edge. (1 <= u <v <= n ). Output corresponds to two rows Output for each test sample. The first row is in the format of "Case #: W", where '#' indicates the test samples (starting from 1 ), W is the number of m-colored schemes. Sample Input 15 8 51 21 31 42 32 42 53 44 5 Sample Output Case 1: 360 Author Eapink solution: # include <iostream> using namespace std; # define N 100int m, n, M, a [N] [N], x [N], textNum; int static sum = 0; bool OK (int k) {for (int j = 1; j <= n; j ++) if (a [k] [j] & (x [j] = x [k]) return false; return true ;} void backtrack (int t) {if (t> n) {sum ++; // for (int I = 1; I <= n; I ++) // cout <x [I] <""; // cout <endl;} else for (int I = 1; I <= m; I ++) {x [t] = I; if (OK (t) backtrack (t + 1); x [t] = 0 ;}} int main () {int I, j, z = 1; cin> textNum; // enter the number of tests while (textNum> 0) {cin> n; // enter the number of vertices for (I = 1; I <= n; I ++) for (j = 1; j <= n; j ++) a [I] [j] = 0; cin> M> m; // number of input edges and number of available colors for (int k = 1; k <= M; k ++) // generate the graph's Adjacent matrix {cin> I> j; a [I] [j] = 1; a [j] [I] = 1 ;} /* for (I = 1; I <= n; I ++) {for (j = 1; j <= n; j ++) cout <a [I] [j] <"; cout <endl;} */for (I = 0; I <= n; I ++) x [I] = 0; backtrack (1); cout <"Case" <z <":" <sum <endl; sum = 0; textNum --; z ++;} return 0 ;}