-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbipartritecheck.cpp
More file actions
62 lines (62 loc) · 1.34 KB
/
bipartritecheck.cpp
File metadata and controls
62 lines (62 loc) · 1.34 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;
typedef long long ll;
vector<int> graph[2002];
bitset<2002> color,visited;
bool bfs(int start){
color.reset();
visited.reset();
queue<int> q;
q.push(start);
if(!visited[start])
color[start]=1;
while(!q.empty()){
int x = q.front();
q.pop();
for(int i=0;i<graph[x].size();++i){
if(!visited[graph[x][i]]){
visited[graph[x][i]]=1;
color[graph[x][i]]= !color[x];
q.push(graph[x][i]);
}
else if(visited[graph[x][i]]&&color[graph[x][i]]==color[x])
return false;
}
}
return true;
}
int main(int argc, char const *argv[])
{
int t,temp;
bool flag=0;
cin>>t;
temp=t;
while(t--){
for(int i=0;i<2002;++i)
graph[i].clear();
flag=0;
int n,m;
cin>>n>>m;
for (int i = 0; i < m; ++i)
{
int t1,t2;
cin>>t1>>t2;
graph[t1].push_back(t2);
graph[t2].push_back(t1);
}
for (int i = 1; i <=n; ++i)
{
if(!bfs(i)){
cout<<"Scenario #"<<temp-t<<":\n";
cout<<"Suspicious bugs found!\n";
flag=1;
break;
}
}
if(!flag){
cout<<"Scenario #"<<temp-t<<":\n";
cout<<"No suspicious bugs found!\n";
}
}
return 0;
}