hdu 1829 A Bug's Life(并查集)
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
Sample Output
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iterator>
#include<utility>
#include<sstream>
#include<iostream>
#include<cmath>
#include<stack>
using namespace std;
const int INF=;
const double eps=0.00000001;
int d[];
int root(int a)
{
while(d[a]!=a) a=d[a];
return a;
}
int main()
{
int T,kase=;
cin>>T;
while(T--)
{
int N,M;
cin>>N>>M;
for(int i=;i<=*N;i++) d[i]=i;
bool ok=true;
for(int i=;i<=M;i++)
{
int from,to;
scanf("%d%d",&from,&to);
if(!ok) continue;
int ra=root(from);
int rb=root(to);
if(ra==rb) ok=false; //判断是否为同性恋
ra=root(from);
rb=root(to+N);
d[ra]=rb; //合并
ra=root(from+N);
rb=root(to);
d[ra]=rb;
}
printf("Scenario #%d:\n",++kase); if(!ok) cout<<"Suspicious bugs found!"<<endl;
else cout<<"No suspicious bugs found!"<<endl;
printf("\n");
}
return ;
}
hdu 1829 A Bug's Life(并查集)的更多相关文章
- 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条臭 ...
 - 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany
		
先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...
 - hdu 5458 Stability(树链剖分+并查集)
		
Stability Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Total ...
 - [HDU 3712] Fiolki (带边权并查集+启发式合并)
		
[HDU 3712] Fiolki (带边权并查集+启发式合并) 题面 化学家吉丽想要配置一种神奇的药水来拯救世界. 吉丽有n种不同的液体物质,和n个药瓶(均从1到n编号).初始时,第i个瓶内装着g[ ...
 - HDU 1829  A Bug's Life (种类并查集)
		
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Oth ...
 - hdu   1829   A Bug's Life(分组并查集(偏移量))
		
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
 - HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
		
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
 - HDU 1829 - A Bug's Life
		
Problem Description Background Professor Hopper is researching the sexual behavior of a rare species ...
 - hdu 5652 India and China Origins 并查集
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5652 题目大意:n*m的矩阵上,0为平原,1为山.q个询问,第i个询问给定坐标xi,yi,表示i年后这 ...
 
随机推荐
- Visual Studio 2012 编译C++显示cl命令
			
为了用newlisp来实现VC编译,以便用我的Emacs开发VC程序,而不需要再打开VS 2012, 需要自己实现命令行的编译.我不需要nmake,因为我想直接了解VC编译器,以便今后更好的驾驭它. ...
 - (转)iOS Wow体验 - 第八章 - 易用性与自动化技术
			
本文是<iOS Wow Factor:Apps and UX Design Techniques for iPhone and iPad>第八章译文精选,也是全书译文的最后一篇.上一篇:W ...
 - mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
			
权限问题,授权 给 root 全部sql 权限 mysql> grant all privileges on *.* to root@"%" identified by & ...
 - [RxJS] Updating Data with Scan
			
You often need to update the data flowing through the stream with custom logic based on what you nee ...
 - [Regular Expressions] Find Repeated Patterns
			
Regular Expression Quantifiers allow us to identify a repeating sequence of characters of minimum an ...
 - 页面显示磁盘空间使用情况-Agedu
			
下载:http://www.chiark.greenend.org.uk/~sgtatham/agedu/ [root@localhost ~]# tar zxvf agedu-r9723.tar.g ...
 - Java中Thread类的start()和run()的区别
			
1.start()方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面的代码. 通 过调用Thread类的start()方法来启动一个线程,这时此线程是处于就绪 ...
 - linux下安装软件的方法
			
1. 区分 rpm -qi -qf -ql -qa四个不同选项组合的作用?rpm -qi //查询已经安装的某个RPM软件包的信息rpm -qf //查询某个程序文件是由哪个RPM软件包安装的rpm ...
 - 限制内容长度(CSS,jQuery)
			
CSS(宽度限制在100px之内,超出就会点点点) <style type="text/css"> p{width: 100px;display: inline-blo ...
 - DevExpress ASPxHtmlEditor控件格式化并导出Word (修复中文字体导出丢失)
			
在前台页面中先插入一个ASPxHtmlEditor控件,名为ASPxHtmlEditor1. 我用的Dev版本为14.1 格式化文本 在后台插入如下代码 1 const string css ...