-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoloring.cpp
74 lines (63 loc) · 1.49 KB
/
coloring.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
65
66
67
68
69
70
71
72
73
74
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
class graph{
int v;
std::vector<int> *adj ;
public:
graph(int V);
void addv(int a ,int b);
void colour(int n);
};
graph::graph(int V){
this->v = V;
adj = new vector<int>[V];
}
void graph::addv(int a,int b){
adj[a].push_back(b);
adj[b].push_back(a);
}
int minpallet(bool used[],int n){
for(int i=0;i<n;i++){
if(used[i])
return i;
}
}
void graph::colour(int n){
// int pallet[n];
bool used[n][n],visited[n];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
used[i][j] =true;
}
}
int st = 0;
for(int i = 0;i<n;i++){
vector<int>::iterator it;
for(it = adj[i].begin();it!=adj[i].end();it++){
used[*it][minpallet(used[i],n)] = false;
}
}
for(int i=0;i<n;i++)
cout<<i<<":"<<minpallet(used[i],n)<<" ";
}
int main(){
int n;
cin>>n;
graph g(n);
int a=1;int x,y;
while(a==1){
cout<<"Enter vertices ";
cin>>x>>y;
g.addv(x,y);
cout<<"More? 1/0 ";
cin>>a;
}
g.colour(n);
return 0;
}