hdu 1829 A Bug's Life
来源:互联网 发布:微信mac版 dmg 编辑:程序博客网 时间:2024/05/27 00:45
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 15767 Accepted Submission(s): 5163
Problem 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
23 31 22 31 34 21 23 4
Sample Output
Scenario #1:Suspicious bugs found!Scenario #2:No suspicious bugs found!HintHuge input,scanf is recommended.
给出许多对性别不同的组合,问有无同性恋,每输入一组x,y,为异性,那么x+n与y应该属于同一性别,y+n与x应该为同一性别,每次检测一下x与x+n,y与y+n的根节点是否相同即可,相同则意味着存在同性恋。
#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<iomanip>#include<cstdio>using namespace std;int pre[2222222];int flag=0;int city,road;int find(int x){ if(x==pre[x])return x; pre[x]=find(pre[x]); return pre[x]; }void merge(int x,int y){ int fx=find(x); int fy=find(y); if(fx!=fy) pre[fy]=fx;}int main(){ int a,b; int T; cin>>T; int acse=0; while(T--) { acse++; cin>>city>>road; int i; for(i=0;i<=city*2;i++) pre[i]=i; flag=0; for(i=1;i<=road;i++) { scanf("%d%d",&a,&b); merge(a,b+city); merge(b,a+city); if(find(a)==find(a+city)||find(b)==find(b+city)) flag=1; } cout<<"Scenario #"<<acse<<":"<<endl; if(flag)cout<<"Suspicious bugs found!"<<endl<<endl; else { cout<<"No suspicious bugs found!"<<endl<<endl; } } return 0;}
阅读全文
0 0
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- hdu 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- hdu 1829 A bug’s life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- HDU 1829 A Bug's Life
- A Bug's Life-HDU-1829
- hdu 2818 Building Block
- C++中栈区 堆区 常量区
- 如何从乱码中恢复 (下)
- linux 应用调试
- LintCode 二进制求和
- hdu 1829 A Bug's Life
- Linux上mysql登陆错误解决办法ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/
- 树(树,二叉树,二叉查找树)
- UCI数据集使用
- hihocoder1089
- Sublime Text 3 3126 注册码
- 39. Combination Sum
- hdu 5858 Hard problem
- 给定一个数组,值全是正数,请返回累加和为给定值k的最长子数组长度。