# A Bug

A Bug

Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.

The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.

The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.

``````2
3 3
1 2
2 3
1 3
4 2
1 2
3 4``````

``````Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!
``````

``````#include<iostream>
#include<queue>
#include<utility>
#include<set>
using namespace std;

int maxRow, maxCol;
pair <int, int> start;
pair <int, int> end;
int sr, sc, er, ec;
int r[] = {0, 0, 1, -1};
int c[] = {1, -1, 0, 0};
char graph[110][110];

int bfs() {
set < pair <int, int> > s;
queue < pair <int, int> > que;
queue < int > move;
pair < int, int > posi;
pair < int, int > step[4];
que.push(start);
move.push(0);
int visited = 0;
int moving;
while(1) {
if(que.empty()) return -1;
posi = que.front();
moving = move.front();
//cout << posi.first << ' ' << posi.second << ' ' << moving << endl;
que.pop();
move.pop();
if(graph[posi.first][posi.second] == 'E') return moving;
visited = moving+1;
for(int i=0; i<4; i++) step[i] = posi;
step[0].first++;
step[1].first--;
step[2].second++;
step[3].second--;
for(int i=0; i<4; i++) {
if(step[i].first < 0 || step[i].first >= maxRow) continue;
if(step[i].second < 0 || step[i].second >= maxRow) continue;
if(s.find(step[i]) != s.end()) continue;
if(graph[step[i].first][step[i].second] == '#') continue;
que.push(step[i]);
move.push(visited);
s.insert(step[i]);
}
}
return -1;
}

int main(void) {
int tcase;
cin >> tcase;
while(tcase--) {
cin >> maxRow >> maxCol;
for(int i=0; i<maxRow; i++) {
for(int j=0; j<maxCol; j++) {
cin >> graph[i][j];
if(graph[i][j] == 'S') { start.first = i; start.second = j; }
if(graph[i][j] == 'E') { end.first = i; end.second = j; }
}
}
cout << bfs() << endl;
}
}

``````

``````#include<iostream>
#include<queue>
#include<utility>
#include<set>
using namespace std;

int maxRow, maxCol;
pair <int, int> start;
pair <int, int> end;
int sr, sc, er, ec;
int r[] = {0, 0, 1, -1};
int c[] = {1, -1, 0, 0};
char graph[110][110];

int bfs() {
set < pair <int, int> > s;
queue < pair <int, int> > que;
queue < int > move;
pair < int, int > posi;
pair < int, int > step[4];
que.push(start);
move.push(0);
int visited = 0;
int moving;
while(1) {
if(que.empty()) return -1;
posi = que.front();
moving = move.front();
//cout << posi.first << ' ' << posi.second << ' ' << moving << endl;
que.pop();
move.pop();
if(graph[posi.first][posi.second] == 'E') return moving;
visited = moving+1;
for(int i=0; i<4; i++) step[i] = posi;
step[0].first++;
step[1].first--;
step[2].second++;
step[3].second--;
for(int i=0; i<4; i++) {
if(step[i].first < 0 || step[i].first >= maxRow) continue;
if(step[i].second < 0 || step[i].second >= maxRow) continue;
if(s.find(step[i]) != s.end()) continue;
if(graph[step[i].first][step[i].second] == '#') continue;
que.push(step[i]);
move.push(visited);
s.insert(step[i]);
}
}
return -1;
}

int main(void) {
int tcase;
cin >> tcase;
while(tcase--) {
cin >> maxRow >> maxCol;
for(int i=0; i<maxRow; i++) {
for(int j=0; j<maxCol; j++) {
cin >> graph[i][j];
if(graph[i][j] == 'S') { start.first = i; start.second = j; }
if(graph[i][j] == 'E') { end.first = i; end.second = j; }
}
}
cout << bfs() << endl;
}
}

``````