1829 A Bug's Life
A Bug's Life
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9223 Accepted Submission(s): 2965
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.
Huge input,scanf is recommended.
#include<stdio.h>
#include<string.h>
int f[];
int dis[]; int find(int x)
{
int t;
if(f[x]==x)
return x; t=find(f[x]);
dis[x]=(dis[x]+dis[f[x]])%;
f[x]=t;
return t; } int make(int x,int y)
{
int a=find(x);
int b=find(y);
if(a==b)
{
if(dis[x]==dis[y])
return ;
return ;
} f[a]=b;
dis[a]=(dis[x]+dis[y]+)%;
return ; } int main()
{
//freopen("in.txt","r",stdin);
int t,count=;
int n,m;
int i,a,b,flag;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(dis,,sizeof(dis)); for(i=;i<=n;i++)
f[i]=i; flag=;
for(i=;i<m;i++)
{
scanf("%d%d",&a,&b);
if(make(a,b))
{
flag=;
}
} printf("Scenario #%d:\n",count++);
if(flag)
printf("Suspicious bugs found!\n");
else
printf("No suspicious bugs found!\n");
printf("\n");
}
return ;
}
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(分组并查集(偏移量))
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 (并查集)&&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 1829 A Bug's Life(并查集)
A Bu ...
- HDU 1829 - A Bug's Life
Problem Description Background Professor Hopper is researching the sexual behavior of a rare species ...
- HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
- hdoj 1829 A bug's life 种类并查集
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 并查集的一个应用,就是检测是否存在矛盾,就是两个不该相交的集合有了交集.本题就是这样,一种虫子有 ...
- HDU 1829 A Bug's Life(种类并查集)
思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...
随机推荐
- SharedPreferences的基本用法
获取SharedPreferences的两种方式: 1 调用Context对象的getSharedPreferences()方法 2 调用Activity对象的getPreferences()方法 两 ...
- js实现checkbox的全选/取消
所有的操作都将使用jquery进行. 主要是为了实现指定内容的批量/单独删除操作. 先看一下页面的设计. 实现操作的主要地方是: 首先实现单击“标题”旁的checkbox实现所有条目的选择. 要点:j ...
- PHP获取Cookie模拟登录CURL
要提取google搜索的部分数据,发现google对于软件抓取它的数据屏蔽的厉害,以前伪造下 USER-AGENT 就可以抓数据,但是现在却不行了.利用抓包数据发现,Google 判断了 cookie ...
- Jquery 在动态元素上绑定事件
弄了很久却没有弄出来,感觉没有错,但是动态元素上的事件根本就不响应,代码如下: <input type="button" id="btnyes" valu ...
- Qt在VS2010的安装与配置
1. 下载Qt的安装包和VS2010的Qt插件 2. 安装Qt SDK 点击下载安装包,一路回车即可,主要注意Qt的安装路径最好安装在全英文路径而且中间没有空格, 安装好后,可以运行开始菜单里面的Qt ...
- 使用RX方式模拟DoubanFm的登陆
WP7下的Get Post都是异步的 关于RX http://www.cnblogs.com/yangecnu/archive/2012/11/03/Introducting_ReactiveExte ...
- 【转】 申请对齐某种结构体大小的buffer
在大多数情况下,编译器和C库透明地帮你处理对齐问题.POSIX 标明了通过malloc( ), calloc( ), 和 realloc( ) 返回的地址对于任何的C类型来说都是对齐的.在Linux中 ...
- WPF-控件-ControlTemplate生成的控件
<Window x:Class="由ControlTemplate生成的控件.MainWindow" xmlns="http://schemas.microsoft ...
- 关于php框架
最近学习yii2.0 强哥原班人马开发,不得不看 同时也需要关注一下drupal8和symfony2
- MVC学习系列——ActionResult扩展
首先,MVC扩展性非常强. 我从ActionResult扩展入手,因为我们知道微软ActionResult和其子类,有时候并不能满足所有返回值. 比如:我需要返回XML. 因此,现在我扩展XMLRes ...