-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.COLOR.CPP
64 lines (61 loc) · 960 Bytes
/
11.COLOR.CPP
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
#include<iostream>
using namespace std;
#include<conio.h>
int i,j,m,n,x[5],g[5][5];
void nextvalue(int k);
void mcoloring(int k)
{
do
{
nextvalue(k);
if(!x[k])
break;
if(k==n)
{
for(int i=1;i<=n;i++)
cout<<x[i]<<' ';
cout<<endl;
}
else
mcoloring(k+1);
}
while(1);
}
void nextvalue(int k)
{
do
{
x[k]=(x[k]+1)%(m+1);
if(!x[k])
return;
for(int j=1;j<=k-1;j++)
{
if((g[k][j]!=0) && (x[k]==x[j]))
break;
}
if(j==k)
return;
}
while(1);
}
int main()
{
cout<<"Enter vertext number: ";
cin>>n;
cout<<"Enter Color number : ";
cin>>m;
for(i=1;i<=n;i++)
x[i]=0;
cout<<"\nEnter edge info\n\n";
for(i=1;i<n+1;i++)
{
for(j=1;j<n+1;j++)
{
cout<<"Edge from vertex "<<i<<"To vertex"<<j<<" :";
cin>>g[i][j];
}
cout<<"\n";
}
mcoloring(1);
getch();
}