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.
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.
Input
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.
Output
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.
Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Sample Output
Scenario #1:
Suspicious bugs found! Scenario #2:
No suspicious bugs found!
Hint
Huge input,scanf is recommended.
题解:有N个虫子 只有异性交配才是正常的 但我们不知道哪个虫子的性别是什么 给出M个交配事件 问能否发现同性交配的事件(种类并查集)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
const int N=;
const int mod=1e9+;
int n,q;
int fath[],a[];
void init()
{
for(int i=;i<=n;i++){
fath[i]=i;
a[i]=;
}
}
int findd(int x)
{
if(x==fath[x])return x;
int y=findd(fath[x]);
a[x]=(a[x]+a[fath[x]])&;
fath[x]=y;
return y;
}
bool SetUnion(int x,int y)
{
int fx=findd(x);
int fy=findd(y);
if(fx==fy){
if(a[x]==a[y]) return true;
else return false;
}
fath[fx]=fy;
if(a[y]){
a[fx]=a[x];
}
else{
a[fx]=-a[x];
}
return false;
}
int main()
{
int t,case1=,x,y;
scanf("%d",&t);
while(t--){
bool flat=true;
scanf("%d%d",&n,&q);
init();
for(int i=;i<q;i++){
scanf("%d%d",&x,&y);
if(SetUnion(x,y))flat=false;
}
printf("Scenario #%d:\n",case1++);
if(!flat)puts("Suspicious bugs found!\n");
else puts("No suspicious bugs found!\n");
}
return ;
}