-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path2.bicoloring.cpp
More file actions
62 lines (50 loc) · 1.08 KB
/
2.bicoloring.cpp
File metadata and controls
62 lines (50 loc) · 1.08 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<bits/stdc++.h>
using namespace std;
char visited[100];
vector < int > G[1000];
bicoloring(int s, int n) {
for(int i = 1; i <= n; i++) {
visited[i] = 'w';
}
queue < int > Q;
Q.push(s);
visited[s] = 'r';
while(!Q.empty()) {
int u = Q.front();
Q.pop();
for(int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if(visited[v] == 'w') {
if(visited[u] == 'r') {
visited[v] = 'b';
}
else {
visited[v] = 'r';
}
Q.push(v);
}
if(visited[u] == visited[v]) {
return false;
}
}
}
return true;
}
int main() {
int edge, n;
cout << "Enter edge and node number\n" << endl;
cin >> edge >> n;
for(int i = 1; i <= edge; i++) {
cout << "Edge " << i << endl;
int x, y;
cin >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
if(bicoloring(1,n)) {
cout << "True";
}
else {
cout << "False";
}
return 0;}