Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created September 19, 2016 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chermehdi/f8273067ce87631553943bbefaabe3ec to your computer and use it in GitHub Desktop.
Save chermehdi/f8273067ce87631553943bbefaabe3ec to your computer and use it in GitHub Desktop.
Spoj BugsLife Solution
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <queue>
#define INF 999999
#define in(a,b) ( (b).find(a) != (b).end())
#define clr(a,b) memset((a), (b), sizeof((a)))
#define pb push_back
#define all(a) a.begin(), a.end()
/**
*
* @Author Mehdi Maick
*/
using namespace std;
int main(int argc , char* argv[]) {
int n , m;
int t;
cin >> t;
int ts = 1;
bool visited[2010];
int color[2010];
while (t--){
cin >> n >> m;
printf("Scenario #%d:\n",ts++);
vector<vector<int> > v(n+1);
int a,b ;
for (int i = 0; i < m; i++) {
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
clr(visited, false);
for (int i = 0; i < 2010; i++) {
color[i] = -1;
}
queue<int> q;
for (int i = 1; i <= n; i++) {
if(!visited[i]){
color[i] = 1;
visited[i] = true;
q.push(i);
while(!q.empty()){
int node = q.front();
q.pop();
for(auto it: v[node]){
if(color[it] != -1 && color[it] == color[node]){
cout <<"Suspicious bugs found!" << endl;
goto label;
}
if(!visited[it]){
q.push(it);
if(color[it] == -1)
color[it] = 1 - color[node];
visited[it] = true;
}
}
}
}
}
cout << "No suspicious bugs found!" << endl;
label:;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment