[poj2492]A Bug's Life(并查集+补集)
| Time Limit: 10000MS | Memory Limit: 65536K | |
| Total Submissions: 34678 | Accepted: 11339 |
Description
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
Output
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
Source
#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(并查集+补集)的更多相关文章
- hdu 1829 A Bug's Life(并查集)
A Bu ...
- HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- J - A Bug's Life 并查集
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- nyoj 209 + poj 2492 A Bug's Life (并查集)
A Bug's Life 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Background Professor Hopper is researching th ...
- poj 2492A Bug's Life(并查集)
/* 目大意:输入一个数t,表示测试组数.然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配. 要求统计交配过 ...
- 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条臭 ...
- POJ 2492 A Bug's Life 并查集的应用
题意:有n只虫子,每次给出一对互为异性的虫子的编号,输出是否存在冲突. 思路:用并查集,每次输入一对虫子后就先判定一下.如果两者父亲相同,则说明关系已确定,再看性别是否相同,如果相同则有冲突.否则就将 ...
- 并查集补集作法 codevs 1069 关押罪犯
1069 关押罪犯 2010年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description ...
- [poj1182]食物链(并查集+补集)
食物链 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 64841 Accepted: 19077 Description ...
随机推荐
- jquery+ajax实现分页
var curPage = 1; //当前页码 var total,pageSize,totalPage; //总记录数,每页显示数,总页数 getData(1); $("#pagecoun ...
- Java中对象创建过程
本文介绍的对象创建过程仅限于普通Java对象,不包括数组和Class对象. 1.类加载检查 虚拟机遇到一条new指令时,首先去检查该指令的参数能否在常量池中定位到一个类的符号引用,并且检查这个符号引用 ...
- Redis与Memcache的区别
Redis与Memcache的区别 数据类型: redis数据类型丰富,支持set liset等类型 memcache支持简单数据类型,需要客户端自己处理复杂对象 持久性: red ...
- 用于基于 RPM 的 Linux 平台的 Java
成为超级用户,方法是运行 su 并输入超级用户口令. 卸载任何之前安装的 Java 程序包. rpm -e package_name 切换到所需的安装目录.键入:cd directory_path_n ...
- linux昨天修改的文件
find ./ -mtime :返回最近24小时内修改过的文件. find ./ -mtime : 返回的是前48~24小时修改过的文件.而不是48小时以内修改过的文件. Linux查找文件内容的常用 ...
- Linux下gcc与gdb简介
gcc编译器可以将C.C++等语言源程序.汇编程序编译.链接成可执行程序.gdb是 GNU 开发的一个Unix/Linux下强大的程序调试工具. linux下没有后缀名的概念.但 gcc 根据文件的后 ...
- 【转】Python练习,网络爬虫框架Scrapy
一.概述 下图显示了Scrapy的大体架构,其中包含了它的主要组件及系统的数据处理流程(绿色箭头所示).下面就来一个个解释每个组件的作用及数据的处理过程. 二.组件 1.Scrapy Engine(S ...
- 移动设备如何打开RMS加密的文档
关键字:RMS. AZure RMS.IPhone.Android.Office365.Sharepoint.Exchange 最近总是碰到要求用苹果手机及安卓手机阅读RMS加密文档的需求,经过查找相 ...
- 如何使用iTunes与iTools导出微信聊天记录
.tocblock .tocblock .tocblock { margin-left: 2.25em; } .madoko .toc>.tocblock .tocblock { margin- ...
- Yii2中多表关联查询(join、joinwith)
我们用实例来说明这一部分 表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_name ...