A Bug's Life
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 49835 | Accepted: 16094 |
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.
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!
A Bug's Life
Time Limit: 10000MS | Memory Limit: 65536K | |
Total Submissions: 49835 | Accepted: 16094 |
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.
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
#. 1 Scenario: ! Suspicious bugs found Scenario # 2: ! No bugs found suspicious
Title: T a sample, each sample, representative of a first row of n points n, m a query. The next two numbers m lines each x, y. Represent x, y opposite sex, ask the current test sample inquiry there was anything wrong.
Ideas: the feeling of belonging to the vector of the water problem, and simpler than the food chain, this question d represent only two values, 0 and 0 on behalf of the same sex, a representative of the opposite sex, note change of time plus 2. d
output format for each end of the test a multi-output space, d Remember cleared (WA1 fat)
#include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <map> #include <iomanip> #include <algorithm> #include <queue> #include <stack> #include <set> #include <vector> //const int maxn = 1e5+5; #define ll long long ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} #define MAX INT_MAX #define FOR(i,a,b) for( int i = a;i <= b;++i) #define bug cout<<"--------------"<<endl using namespace std; int fa[41000],d[41000]; int Find(int x) { if(fa[x] == x) return x; int root = Find(fa[x]); d[x] = (d[x] + d[fa[x]] + 2) % 2; return fa[x] = root; } int main() { int T; scanf("%d",&T); for(int t = 1;t<=T;++t) { int flag = 0; int n,m; scanf("%d%d",&n,&m); for(int i =1;i<=n;++i) fa[i] = i; memset(d,0,sizeof(d)); for(int i=1;i<=m;++i) { int x,y; scanf("%d%d",&x,&y); if(flag == 1) continue; int fx = Find(x),fy = Find(y); if(fx == fy){ if((d[x] + d[y] +2) % 2 != 1) flag = 1; } else { fa[fy] = fx; d[fy] = (d[x] + d[y] + 1 + 2) % 2; } } if(flag == 1) printf("Scenario #%d:\nSuspicious bugs found!\n\n",t); else printf("Scenario #%d:\nNo suspicious bugs found!\n\n",t); } }