HDU 1829 - A Bug's Life
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.
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Suspicious bugs found!
Scenario #2:
No suspicious bugs found!
Huge input,scanf is recommended.
#include <cstdio>
using namespace std;
int f[+],num[+],t,n,m,a,b,fa,fb;
int sf(int x){
if(x==f[x]) return x;
else {
int fx=sf(f[x]);
num[x]=(num[x]+num[f[x]])%;
return f[x]=fx;
}
}
int main(){
scanf("%d",&t);
for(int k=;k<=t;k++){
printf("Scenario #%d:\n",k);
scanf("%d%d",&n,&m); bool flag=;
for(int i=;i<=n;i++) f[i]=i,num[i]=;
for(int i=;i<=m;i++){
scanf("%d%d",&a,&b);
if(flag){
fa=sf(a); fb=sf(b);
if(fa==fb){ if((num[a]-num[b]+)%!=) flag=;}//避免负数
else f[fb]=fa,num[fb]=(num[a]-num[b]++)%;
}
}
if(flag) puts("No suspicious bugs found!\n");
else puts("Suspicious bugs found!\n");
} return ;
}
HDU 1829 - A Bug's Life的更多相关文章
- 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 (并查集)&&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(分组并查集(偏移量))
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 (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany
先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...
- 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 ...
- HDU 1829 A Bug's Life(种类并查集)
思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...
- hdu 1829 &poj 2492 A Bug's Life(推断二分图、带权并查集)
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 1829/POJ 2492 A Bug's Life
A Bug's Life Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- session的存储方式和配置
Session又称为会话状态,是Web系统中最常用的状态,用于维护和当前浏览器实例相关的一些信息.我们控制用户去权限中经常用到Session来存储用户状态,这篇文章会讲下Session的存储方式.在w ...
- C# 和Java的foreach的不同用法
循环语句为苦逼的程序猿们提供了很大的便利,有while.do...while.for和 foreach.而且foreach语句很简洁,但是它的优点不仅仅在于此,它的效率也是最高的. 作为两个开发语言, ...
- SERVERPROPERTY方法说明
SERVERPROPERTY 返回有关服务器实例的属性信息. 语法 SERVERPROPERTY ( propertyname ) 参数 propertyname 是包含要返回的服务器属性信息的表达式 ...
- HDU 5145 - NPY and girls
题意: cases T(1≤T≤10) (0<n,m≤30000) (0<ai≤30000) n个数ai 表示n个女孩所在教室 m次询问 [L,R](1 <= L <= ...
- W - stl 的 优先队列 Ⅲ
Description In a speech contest, when a contestant finishes his speech, the judges will then grade h ...
- [Effective Modern C++] Item 5. Prefer auto to explicit type declarations - 相对显式类型声明,更倾向使用auto
条款5 相对显式类型声明,更倾向使用auto 基础知识 auto能大大方便变量的定义,可以表示仅由编译器知道的类型. template<typename It> void dwim(It ...
- 浅说CPU并行计算与GPU并行计算
最近在学一门课,叫做“C++与并行计算”.要用到多CPU(进程)并行的原理,实现语言是C++的MPI接口.联想到上学期用到CUDA C/C++来做并行计算,就对这两门语言做一个总结,分享下自己关于并行 ...
- 运行加速多线程和GPU
http://blog.csdn.net/augusdi/article/details/11883003
- Windows下安装PHP扩展及资源下载地址(memcached为例)
官方下载的php安装包ext目录里以经包含了常用的php扩展,但某些情况下并不能满足我们项目需求,比如memcache扩展就不在官方的php安装包里.这时就需要我们自己去下载安装. 本文列出php官方 ...
- SharePoint 2013 实战碎嘴(ECMAScript客户端对象模型): 提示某个列表不存在
简单情景描述1:(在Sharepoint 2013 Solution 中) 在相应的.aspx页面引入 一下两个.js文件: <script type="text/javascript ...