forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBipartite.cpp
More file actions
82 lines (68 loc) · 1.36 KB
/
Bipartite.cpp
File metadata and controls
82 lines (68 loc) · 1.36 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Bipartite Graph Test
//By coloring of nodes
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define f(i, a, n) for (i = a; i < n; i++)
#define fe(i, a, n) for (i = a; i <= n; i++)
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define mod 1000000007
#define ps(x, y) fixed << setprecision(y) << x
void sks()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
vector<int> adj[100001];
int vis[100001], col[100001];
bool dfs(int node, int c)
{
vis[node] = 1;
col[node] = c;
for (int child : adj[node])
{
if (vis[child] == 0)
{
bool temp = dfs(child, c ^ 1);
if (temp == false)
return false;
}
else
{
if (col[node] == col[child])
return false;
;
}
}
return true;
}
int main()
{
sks();
int n, e, a, b, i;
cin >> n >> e;
f(i, 0, e)
{
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
bool val = dfs(1, 1);
if (val == true)
cout << "Graph is Bipartite";
else
cout << "Graph is not Bipartite";
return 0;
}