-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_coloring.cpp
More file actions
67 lines (53 loc) · 1.2 KB
/
graph_coloring.cpp
File metadata and controls
67 lines (53 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define MAX 1000
#define m 3
int ou=1;
int x[MAX]={0};
int g[MAX][MAX];
int edges;
void nextvalue(int k) {
while (1) {
int j;
x[k] = (x[k] + 1) % (m + 1);
if (x[k] == 0)
return;
for (j = 0; j < edges; j++) {
if ((g[k][j] != 0) && (x[k] == x[j]))
break;
}
if (j == edges)
return;
}
}
void mcoloring(int k) {
while (1) {
nextvalue(k);
if (x[k] == 0)
return;
if (k == edges - 1) {
printf("output:%d \n", ou++);
for (int i = 0; i < edges; i++) {
printf("vertex %d -> color %d\t", i, x[i]);
}
printf("\n");
} else {
mcoloring(k + 1);
}
}
}
int main() {
printf("Enter the number of edges: ");
scanf("%d", &edges);
printf("Enter the adjacency matrix: \n");
for (int i = 0; i < edges; i++) {
// printf("Enter values for edge %d:\n", i);
for (int j = 0; j < edges; j++) {
scanf("%d", &g[i][j]);
}
}
int k = 0;
mcoloring(k);
return 0;
}