-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
62 lines (61 loc) · 1.05 KB
/
graph.cpp
File metadata and controls
62 lines (61 loc) · 1.05 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
#include<stdio.h>
#include<conio.h>
int x[50],g[50][50],n,i,j,m;
void next_value(int k)
{
while(1)
{
x[k]=(x[k]+1)%(m+1);
if(x[k]==0)
return;
for(j=1;j<=n;j++)
{
if(g[k][j]!=0&&(x[k]==x[j]))
break;
}
if(j==n+1)
return;
}
}
void coloring(int k)
{
do
{
next_value(k);
if(x[k]==0)
return;
if(k==n)
{
for(i=1;i<=n;i++)
printf("vertex %d = color No. %d\t",i,x[i]);
printf("\n");
}
else
coloring(k+1);
}while(k<n-1);
}
int main()
{
int e,k,l;
printf("Enter no. of vertices : ");
scanf("%d",&n);
printf("Enter no. of edges : ");
scanf("%d",&e);
m=n-1;
printf("\nThe maximum possible colours that can be assigned are: %d\n",m);
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
g[i][j]=0;
printf("Enter u and v of an edge\n");
for(i=1;i<=e;i++)
{
printf("\nfor egde %d\n",i);
scanf(" %d %d",&k,&l);
g[k][l]=1;
g[l][k]=1;
}
for(i=0;i<=n;i++)
x[i]=0;
printf("\nThe colouring possibilities are:\n");
coloring(1);
}