[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 ...
随机推荐
- Redis在Linux下的安装和启动和配置
第一步:下载Redis安装包,下载版本:3.0.5 在所在目录右键打开终端输入命令: wget http://download.redis.io/releases/redis-3.0.5.tar.gz ...
- Css深入理解之浮动_慕课网课程笔记
前言 这篇是在慕课网上跟着张鑫旭重走CSS之路的第三篇学习笔记了,主要是学习float属性,闲话少说,下面进入正文. float的历史 要想了解一个东西,我们还是需要从本质去了解它,那么我们就需要问一 ...
- chartControl绑定数据源
private void BindChartControl(DataTable dataTable,ChartControl chartControl,int[] columnNO,ViewType ...
- 夺命雷公狗-----React---24--小案例之react经典案例todos(单条任务的删除)
我们的组建分析图 我们组建需要的是删除,数据流方式如下所示: 为了更方便下一步操作,先写个函数他 然后在Ul组建里面对她进行处理 然后在Zong组建里对数据进行处理,如下所示: 但是悲剧的一幕出现了, ...
- struts 文件上传
=================================== 实现单个文件上传 ====================================== 步骤1. 导入jar包: com ...
- Unity 性能
Unity 5.0 AMD 7650k 自带核显 Unity自建立方体2000正方体 50帧 但每个立方体多达60面 多个三角形 每秒100万面绘制 可能每个都要单独计算光照? 导入3ds模型相当于 ...
- python学习笔记之基础二(第二天)
1.编码转换介绍 unicode是最底层.最纯的,会根据终端的编码进行转化展示 一般硬盘存储或传输为utf-8(因为省空间.省带宽),读入内存中为unicode,二者如何转换 a = ' ...
- 跳转 linQ
<a href="../Book/BookDetail?book_id=@book.book_id">@book.book_name</a> query + ...
- XML Schema choice 元素
XSD : <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://w ...
- 2016java技术岗面试题
一.Java基础 1. String类为什么是final的. 2. HashMap的源码,实现原理,底层结构. 3. 说说你知道的几个Java集合类:list.set.queue.map实现类咯... ...