Time Limit: 10000MS   Memory Limit: 65536K
Total Submissions: 33833   Accepted: 11078

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

带偏移量的并查集。

两个集合并时,要注意处理dis数组,使点之间的关系不出错

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int mxn=;
int fa[mxn];
int dis[mxn];
int n,m;
bool flag;
int find(int x){
if(fa[x]==x){
return x;
}
int newfx=find(fa[x]);
dis[x]=(dis[x]+dis[fa[x]])%;
return fa[x]=newfx;
}
bool pd(int a,int b){
int u=find(a),v=find(b);
if(u==v){
if(dis[a]!=(dis[b])^){
flag=;
return ;
}
}
else{
fa[u]=v;
dis[u]=((dis[a]-dis[b])^);
}
return ;
}
void init(int x){
for(int i=;i<=x;i++)fa[i]=i,dis[i]=;
}
int main(){
int T;
scanf("%d",&T);
for(int ro=;ro<=T;ro++){
printf("Scenario #%d:\n",ro);
scanf("%d%d",&n,&m);
init(n);
int i,j;
int x,y;
flag=;
for(i=;i<=m;i++){
scanf("%d%d",&x,&y);
pd(x,y);
}
if(flag)printf("Suspicious bugs found!\n");
else printf("No suspicious bugs found!\n");
printf("\n");
}
return ;
}

POJ2492 A Bug's Life的更多相关文章

  1. [poj2492]A Bug's Life(并查集+补集)

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

  2. poj2492 A Bug's Life【并查集】

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

  3. poj2492 A Bug's Life(带权并查集)

    题目链接 http://poj.org/problem?id=2492 题意 虫子有两种性别,有n只虫子,编号1~n,输入m组数据,每组数据包含a.b两只虫子,表示a.b为不同性别的虫子,根据输入的m ...

  4. POJ2492 A Bug's Life —— 种类并查集

    题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Su ...

  5. POJ2492 A Bug's Life 带权并查集

    分析:所谓带权并查集,就是比朴素的并查集多了一个数组,记录一些东西,例如到根的距离,或者和根的关系等 这个题,权数组为relation 代表的关系  1 和父节点不同性别,0,和父节点同性别 并查集一 ...

  6. poj2492 A Bug's Life【基础种类并查集】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298148.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

  7. hdu1829&&poj2492 A Bug's Life 基础种类并查集

    把性别相同的虫子放在同一个集合,然后每读入一对虫子号,判断它们在不在同一集合,在则同性别,不在则继续 #include <cstdio> #include <cstring> ...

  8. POJ2492 A Bug's Life 判断二分图

    给一个无向图,判断是否为二分图 是否有奇环.用染色法解决,也可以用并查集解决,时间复杂度是相同的,但是并查集用的内存少. 这里给出Bfs染色的代码 #include<iostream> # ...

  9. POJ-2492 A Bug's Life(种类并查集)

    http://poj.org/problem?id=2492 题意: 给出一个T代表几组数据,给出一个n一个m,代表人的编号由1~n,m条命令,每条命令由两个数值组成,代表这两个人性别不同,问所有命令 ...

随机推荐

  1. Linux命令学习-sed

    sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法sed命令行格式为:         sed ...

  2. java 15 -3 集合的遍历的练习

    练习:用集合存储5个动物对象,并把动物对象进行遍历. 分析: A:创建动物类 a:无参构造方法 b:有参构造方法 c:get.set方法 B:创建集合对象 a:Collection animal = ...

  3. FusionCharts V3图表导出图片和PDF属性说明(转)

    百闻不如一见,狠狠点击,快快下载:(演示文档有错误,不提供下载了.待新的演示文档出来.) 许多朋友说上面的DEMO用不了.fusioncharts官方的演示非常不错,就是来不及整理,各位大侠们可以研究 ...

  4. 【夯实Mysql基础】MySQL在Linux系统下配置文件及日志详解

    本文地址 分享提纲: 1. 概述 2. 详解配置文件 3. 详解日志 1.概述 MySQL配置文件在Windows下叫my.ini,在MySQL的安装根目录下:在Linux下叫my.cnf,该文件位于 ...

  5. PHP基础01:环境搭建

    1.只会前端的只是有时候让我感到很苦恼,所以决定从今天开始学习后端,看了一些关于后端语言的比较帖子,决定选择php作为我的第一门后端语言.这个是我自己的学习笔记.方便自己复习,不写下来会太无聊了. 第 ...

  6. Android ViewPager使用详解

    这是谷歌官方给我们提供的一个兼容低版本安卓设备的软件包,里面包囊了只有在安卓3.0以上可以使用的api.而viewpager就是其中之一利用它,我们可以做很多事情,从最简单的导航,到页面菜单等等.那如 ...

  7. Linux第五次学习笔记

    处理器体系结构 Y86指令集体系结构 定义一个指令集体系结构 ,包括定义各种状态元素.指令集和它们的编码.一组编程规范和异常事件处理. 程序员可见的状态 Y86程序中的每条指令都会读取或修改处理器状态 ...

  8. 如何部署Iveely.Computing分布式实时计算系统

    Iveely.Computing是参考Storm的分布式实时计算系统的部分原理,用纯Java实现的轻量级.迷你型,适合于搜索引擎的实时计算系统, Iveely 搜索引擎是一款基于Iveely.Comp ...

  9. Bootstrap系列 -- 20. 禁用状态

    Bootstrap框架的表单控件的禁用状态和普通的表单禁用状态实现方法是一样的,在相应的表单控件上添加属性“disabled” 在使用了“form-control”的表单控件中,样式设置了禁用表单背景 ...

  10. impdp使用

    创建一个dir,dump_dir1,将备份文件放在下面 impdp szfetsc_card/123456 directory=dump_dir1 dumpfile=130912.dmp REMAP_ ...