[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 ...
随机推荐
- haproxy para config
.. from http://www.cnblogs.com/dkblog/archive/2012/03/13/2393321.html 常用配置选项: OPTION 选项: option http ...
- Production环境中iptables常用参数配置
production环境中iptables常用参数配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我相信在实际生产环境中有很多运维的兄弟跟我一样,很少用到iptables的这个 ...
- 在线免费生成 <IDEA>全系列 注册码
body { background: #fff; color: #333; font-family: Consolas, sans-serif; margin: 2em auto; width: 70 ...
- HDU 5063 Operation the Sequence(仔细审题)
http://acm.hdu.edu.cn/showproblem.php?pid=5063 题目大意: 题目意思还是比较简单.所以就不多少了.注意这句话,对解题有帮助. Type4: Q i que ...
- Docker的容器创建以及基本命令
1. 使用docker run创建docker容器,(docker命令都是以docker开头的)安装完docker后,大多数情况下,本机上面一般没有docker镜像的,执行docker run的时候一 ...
- 使用AutoIT对增加和删除文件属性的实现
编写历程: 前段日子,晚上下班回家,一个舍友问我可不可以将一个目录下的隐藏文件全部显示出来(变成非隐藏文件),我说可以. 之后就开始大刀阔斧的寻找方法来做这件事,上网找,说需要一个Windows下的小 ...
- Elasticsearch 聚合
桶(bucket)聚合 满足条件的结果集合.桶可以嵌套 标(metric)聚合 满足条件的结果集合的一些指标.如count,max等.
- oracle细节
1.oracle中NVL的含义: 如果oracle第一个参数为空那么显示第二个参数的值,如果第一个参数的值不为空,则显示第一个参数本来的值. 2.Oracle中in和exists的区别: 1).sel ...
- C# 自动Ping服务
using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; u ...
- include与require的区别?
require()语句的性能与include()相类似,都是包括并运行指定文件.不同之处在于:对include()语句来说,在执行文件时每次都要进行读取和评估:而对于require()来说,文件只处理 ...