A Bug’s Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 32887 Accepted: 10772 Description
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. 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
# include <iostream> # include <stdio.h> # include <string.h> # include <algorithm> const int M= 1005; const int MAX= 100005; const long long int MOD=1000000007; using namespace std; int pre[MAX]; int vis[MAX],n,m; int color[MAX];//0 一个性别 1另一个性别 int ans=1,cnt,q,flag; void ff(int n) { for(int i=1; i<=n; i++) { pre[i]=i; } memset(color,0,sizeof(color)); return ; }
int findi(int x) //理解,加强理解 { int rt; if(x!=pre[x]) { rt=findi(pre[x]); color[x]=color[x]^color[pre[x]]; return pre[x]=rt; } return pre[x]; }
# include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <vector> # include <queue> # define CLR(arr,val) memset(arr,val,sizeof(arr)) using namespace std;
const int N=2005; int color ,n,m; bool vis ; vector<int> map ;
# include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <vector> # define CLR(arr,val) memset(arr,val,sizeof(arr)) using namespace std;
const int N=2003; int n,m,color ; vector<int> map ; bool vis ;