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 ...
随机推荐
- React-Native个人信息界面
最近在做一个小练习项目,用户登陆后需要跳转到用户登录信息界面,加班半个小时终于将界面的布局搞定.接触Rect-Native也有一段时间了,以前没有做过ios,只做过android,就布局和开发效率上来 ...
- achartengine andorid图像引擎入门
最近在帮机械学院开发一个app 用了第三方的图像引擎——achartengine功能还算强大(虽然相比于Html那些第三方图像引擎还是差点不过也够用了) 入门: 参考http://blog.csdn. ...
- BestCoder 2nd Anniversary 1002 Arrange
排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...
- QTestLib Tutorial
本学习指南介绍了如何使用QTestLib框架的一些特性,分为4章: 编写一个单元测试程序 数据驱动测试 模拟GUI事件 重复GUI事件 第一章 编写一个单元测试程序 文件列表: qtestlib/tu ...
- SharePoint 2013 实战碎嘴(ECMAScript客户端对象模型): 提示某个列表不存在
简单情景描述1:(在Sharepoint 2013 Solution 中) 在相应的.aspx页面引入 一下两个.js文件: <script type="text/javascript ...
- Android 桌面生成快捷方式
Android生成桌面快捷方式的几种方法: //------------以下为动态替换桌面应用Icon的一种解决方案------------------- // 1.获取本地目录图片的Bitmap ; ...
- 关于微信小程序的一些思考
### 怎么样理解小程序? * 微信的重点产品* 一个事实OS,目前并不知道小程序的入口在哪里?* 小程序的入口可能在如下三个地方: 1. 发现入口 2. 扫码 3. 搜索框 * 小程序没有关注, 意 ...
- Spring中的DataBinding(一)
DataBinding在Spring中应用. 第一点:使用ModelAttribute指定带绑定的数据内容 很重要的属性:@ModelAttribute([value=""])可以 ...
- MySQL load data infile
语法: load data [low_priority] [local] infile ‘file_path' [replace] [ignore] into table table_name [(c ...
- MYSQL 提取时间中的信息的 4 方法
方法 1. year(),month(),day() 方法 2. dayofweek(),dayofmonth(),dayofyear(); 方法 3. hour(),minute(),second( ...