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 ...
随机推荐
- .NET MySQL的参数化查询
MySqlConnection conn = new MySqlConnection(SqlConnnectString); MySqlCommand cmd = new MySqlCommand(& ...
- CSS学习笔记——CSS中定位的浮动float
昨天在解决了盒模型的问题之后又出现了新的知识模糊点:浮动和绝对定位?今天先解决浮动相关的问题,首先列举出想要解决的问题: 1.浮动到底是怎么样的? 2.浮动对元素的影响有什么? 3.浮动主要用来干什么 ...
- js 进阶笔记
JS中substr和substring的用法和区别 substr和substring都是JS截取字符串函数,两者用法很相近, substr方法 返回一个从指定位置开始的指定长度的子字符串. strin ...
- oracle 通过透明网关gateway 连接sqlserver
真实配置如下: 1.安装gateway 在一台单独的机器上,ip:172.30.40.29 2.配置listener.ora如下: 路径: D:\product\11.2.0\tg_1\NETWOR ...
- REST总结
REST是Roy Thomas Fielding博士于2000年在他的博士论文中阐述的一种架构风格和设计原则.REST并非一种协议或者标准,事实上它只是阐述了HTTP协议的设计初衷:现在HTTP在网络 ...
- javascript中base64和Gzip的使用
一般的使用流程(4步): 服务器端将字符串Gzip压缩为 字节数组——>通过base64转为字符串(后传递到客户端)——>解码base64字符串为字节数组——>Gzip解码字节数组为 ...
- Java代理模式——静态代理模式
一:代理模式 代理模式的作用是:为其他对象提供一种代理以控制这个对象的访问.在某些情况下,一个客户不想或者不能直接引用另一个对象,而代理对象可以在客户端和目标对象之间起到中介的作用. 二:代理模式设计 ...
- mysql 时间戳按指定格式(Y-m-d)取出
之前做采集脚本,把采集的时间按unix时间戳的形式取出 那么在写sql语句的时候,需要按时间查询相应的记录,页面传进来的$time 是'2014-01'之类的字符串,那么怎么写sql呢 $sql ...
- spring下配置dbcp,c3p0,proxool[转]
不管通过何种持久化技术,都必须通过数据连接访问数据库,在Spring中,数据连接是通过数据源获得的.在以往的应用中,数据源一般是Web应用服务器提供的.在Spring中,你不但可以通过JNDI获取应用 ...
- Fragment与Activity
一个Fragment的实例总是和包含它的Activity直接相关. fragment可以通过getActivity() 方法来获得Activity的实例,然后就可以调用一些例如findViewById ...