A Bug's Life
Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 34678   Accepted: 11339

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

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.

Source

TUD Programming Contest 2005, Darmstadt, Germany
 
 
此题同poj1182 http://www.cnblogs.com/Pumbit-Legion/p/5925331.html
 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<algorithm>
#include<queue>
#define LL long long
int fa[],size[];
int n;
inline int read(){
int sum=;char ch=getchar();
while(ch>''||ch<'')ch=getchar();
while(ch<=''&&ch>=''){
sum=sum*+ch-'';
ch=getchar();
}
return sum;
}
inline int fnd(int x){
int r=x;
while(x!=fa[x])x=fa[x];
int tmp;
while(r!=x)tmp=fa[r],fa[r]=x,r=tmp;
return x;
}
inline int uni(int x,int y){
int fx=fnd(x);
int fy=fnd(y);
if(size[fx]<size[fy])fa[fx]=fy;
else if(size[fx]>size[fy])fa[fy]=fx;
else{
fa[fy]=fx;
++size[fx];
}
return ;
}
int main(){
int t,x=;
t=read();
while(x<=t){
printf("Scenario #%d:\n",x);
int i,m;
n=read(),m=read();
memset(size,,sizeof(size[])*n*+);
for(i=;i<=n*;++i)fa[i]=i;
int note=,a,b;
for(i=;i<=m;++i){
a=read(),b=read();
if(!note){
int fa1=fnd(a);
int fb1=fnd(b);
if(fa1==fb1){
note=;
puts("Suspicious bugs found!");
continue;
}
int fa2=fnd(a+n);
int fb2=fnd(b+n);
uni(fa1,fb2);
uni(fa2,fb1);
}
}
if(!note)puts("No suspicious bugs found!");
puts("");
x++;
}
return ;
}

[poj2492]A Bug's Life(并查集+补集)的更多相关文章

  1. hdu 1829 A Bug's Life(并查集)

                                                                                                    A Bu ...

  2. HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  3. J - A Bug's Life 并查集

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  4. nyoj 209 + poj 2492 A Bug's Life (并查集)

    A Bug's Life 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Background  Professor Hopper is researching th ...

  5. poj 2492A Bug's Life(并查集)

    /* 目大意:输入一个数t,表示测试组数.然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配. 要求统计交配过 ...

  6. hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them

    http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...

  7. POJ 2492 A Bug's Life 并查集的应用

    题意:有n只虫子,每次给出一对互为异性的虫子的编号,输出是否存在冲突. 思路:用并查集,每次输入一对虫子后就先判定一下.如果两者父亲相同,则说明关系已确定,再看性别是否相同,如果相同则有冲突.否则就将 ...

  8. 并查集补集作法 codevs 1069 关押罪犯

    1069 关押罪犯 2010年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description ...

  9. [poj1182]食物链(并查集+补集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 64841   Accepted: 19077 Description ...

随机推荐

  1. Spring入门

    Spring可以做很多事情,它为企业级的开发提供了丰富的功能,但是这些功能的底层实现都依赖于它的两个核心特性, 也就是依赖注入(dependency injection, DI)和面向切面编程(asp ...

  2. 寿司点餐系统Sprint1总结

    为期十天的一个冲刺,说长不长,说短不短.从一开始的接收课程任务到第一次聚集讨论. 确定方案.实行方案,再到最后的决定结束第一个冲刺,都是大家一起讨论着加小小的默契一步步 向前.没有完美,但是总体完成的 ...

  3. Linux 挂载U盘

    命令模式下挂载,图形的一般可以自动识别. #fdisk -l      --查看linux 硬盘分区 这个/dev/sdg1 就是我的U盘了,这里挂载的fat格式的 # mount /dev/sdg1 ...

  4. Android 自定义ListView

    本文讲实现一个自定义列表的Android程序,程序将实现一个使用自定义的适配器(Adapter)绑定 数据,通过contextView.setTag绑定数据有按钮的ListView. 系统显示列表(L ...

  5. CCNET+MSBuild+SVN实现每日构建

    最近开始将源代码迁移到SVN,于是便考虑到如何从SVN定期获取源码,自动编译并部署以减轻工作量并提高工作效率.通过多方搜集资料并进行研究,基本实现了这个功能.对于每日构建的概念就不具体展开了,可以在各 ...

  6. 在执行Java命令或eclipse启动程序,提示报错’jvm.cfg无法找到’的解决办法

    一.问题背景 昨天debug代码的时候,突然发现无法启动程序了.每次启动程序的时候均报如下错误:(回家以后重现了下这个问题.发现不同电脑,所在的lib下的文件夹不一样,应该和jdk安装时硬件的情况有关 ...

  7. CocoaPods和git

    CocoaPods是第三方框架的管理工具 CocoaPods 安装使用步骤: 1. 利用 gem 安装 CocoaPods! 1> gem 服务器在国外,提供了非常丰富的终端应用程序! gem ...

  8. 分布式入门之2:Quorum机制

    1.  全写读1(write all, read one) 全写读1是最直观的副本控制规则.写时,只有全部副本写成功,才算是写成功.这样,读取时只需要从其中一个副本上读数据,就能保证正确性. 这种规则 ...

  9. [转]java二维码生成与解析代码实现

    转载地址:点击打开链接 二维码,是一种采用黑白相间的平面几何图形通过相应的编码算法来记录文字.图片.网址等信息的条码图片.如下图 二维码的特点: 1.  高密度编码,信息容量大 可容纳多达1850个大 ...

  10. 写Python脚本语言时,“SyntaxError: Non-ASCII character '\xe6' in file”错误的处理

    如图是一段简单的文件操作代码,以为打开文件"test1221_1.py",若不存在此文件,则创建此文件.接下来并输出相关信息. 当少写了黄色方框圈起来的一行看似不经意的带有编码格式 ...