-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bipertite2.cpp
62 lines (57 loc) · 1 KB
/
Bipertite2.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
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5+7;
vector<int> g[mx];
bool vis[mx];
int color[mx];
void dfs(int node, int col) {
if(vis[node]) return;
vis[node] = 1;
color[node] = col;
for(auto v: g[node]) {
dfs( v, col^1 );
}
return;
}
int main(){
#ifdef LOCAL
ios_base::sync_with_stdio(false),cin.tie(nullptr);
#else
freopen( "in.txt", "r", stdin);
// freopen( "out.txt","w", stdout);
#endif
int n;
cin >> n;
std::vector<pair<int,int>> e;
for(int i = 0; i<n; i++) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
e.push_back({x,y});
}
dfs(1, 0);
for(auto i:e) {
if( color[i.first] == color[i.second]){
cout << "Not Bipertite Graph" << endl;
return 0;
}
}
cout << "Bipertite Graph" << endl;
return 0;
}
/*Input:
4
1 2
2 3
4 2
1 3
output:
Not Bipertite Graph
Input:
3
1 2
2 3
4 2
output:
Bipertite Graph*/