[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 ...
随机推荐
- 编译错误:/usr/bin/ld: cannot find -lz
编译时出现错误/usr/bin/ld: cannot find -lz,安装zlib和zlib-devel yum install zlib yum install zlib-devel
- struts-标签
通用标签 url 动态创建url 属性 value="url" var="压入Map栈的key" action="请求名" method=& ...
- windows API 创建临时文件
创建完临时文件后,即可用C\C++标准函数写入.读取,也可以用API.MFC方法来操作. TCHAR szPathName[MAX_PATH]; TCHAR szFileName[MAX_PATH]; ...
- iOS第三方库管理工具
作者:彷徨iOS 原文地址1:http://iostree.sinaapp.com/?p=78 原文地址2:http://blog.csdn.net/wzzvictory/article/detail ...
- SWFUpload
引用:http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非 ...
- 用node-inspector调试Node.js(转自NOANYLOVE'S BLOG)
原文地址:http://www.noanylove.com/2011/12/node-the-inspector-debugging-node-js/ 用node-inspector调试Node.js ...
- Samba快速配置
Samba是linux,unix,windows之间进行交互操作的软件组件,Sanma是基于GPL协议的自由开源软件. 快速配置samba文件服务器 1.关闭防火墙和SELinux [root@cen ...
- 【笔记】科普createDocumentFragment() 创建文档碎片节点
上一篇文章说到了动态添加文本节点的方法那如果我们要添加多个文本节点或者元素节点呢? 大家可能会想到用循环然后逐个逐个添加 但是别忘了js 还提供了创建一个文本碎片的方法 createDocumentF ...
- 机器学习实战4:Adaboost提升:病马实例+非均衡分类问题
Adaboost提升算法是机器学习中很好用的两个算法之一,另一个是SVM支持向量机:机器学习面试中也会经常提问到Adaboost的一些原理:另外本文还介绍了一下非平衡分类问题的解决方案,这个问题在面试 ...
- Centos搭建Python+Nginx+Tornado+Mysql环境[转载]
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入 ...