-
Notifications
You must be signed in to change notification settings - Fork 8
/
bipartite-graph.cpp
63 lines (62 loc) · 1.52 KB
/
bipartite-graph.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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mkp make_pair
typedef long double ld;
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll t;
cin>>t;
for(ll z=1;z<=t;z++)
{
cout<<"Scenario #"<<z<<":"<<endl;
ll n,m;
cin>>n>>m;
ll x,y;
vector<ll> adj[n+1];
for(ll i=0;i<m;i++)
{
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
vector<ll> color(n+1,-1);
ll flag=0;
for (ll i = 1; i <=n; i++)
{
if (color[i] == -1)
{
queue<ll> q;
q.push(i);
color[i] = 1;
while (!q.empty())
{
ll u = q.front();
q.pop();
for (ll j = 0; j < adj[u].size();j++)
{
if (color[adj[u][j]] == -1)
{
color[adj[u][j]] = 1-color[u];
q.push(adj[u][j]);
}
else if(color[adj[u][j]] == color[u])
{
flag=1;
break;
}
}
}
if(flag==1)
{
cout<<"Suspicious bugs found!"<<endl;
break;
}
}
}
if(flag==0)
cout<<"No suspicious bugs found!"<<endl;
}
return 0;
}