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 ...
随机推荐
- 【Qt】Qt之自定义界面(右下角冒泡)【转】
简述 网页右下角上经常会出现一些提示性的信息,桌面软件中也比较常见,类似360新闻.QQ消息提示一样! 这种功能用动画实现起来很简单,这节我们暂时使用定时器来实现,后面章节会对动画框架进行详细讲解. ...
- SQL允许远程访问
1.打开sqlserver对象资源管理器 右键 方面 常规 服务器配置 RemoteAccessEnabled true RemoteDacEnabled true 2.打开SQL SERVER管理 ...
- centos 普通用户添加sudo权限
本文介绍下,在centos中为普通用户添加sudo权限的方法,供大家学习参考. 在centos中为普通用户增加sudo权限的简单方法,大家参考下. 1,修改/etc/sudoers文件,必须为visu ...
- URI、URL以及URN的区别
首先,URI,是uniform resource identifier,统一资源标识符,用来唯一的标识一个资源.而URL是uniform resource locator,统一资源定位器,它是一种具体 ...
- (转)使用getevent监听Android输入设备文件
尊重原创转载请注明:From AigeStudio(http://blog.csdn.net/aigestudio)Power by Aige 侵权必究! 炮兵镇楼 上一节Android事件分发完全解 ...
- MYSQL创建多张表,相同表结构,不同表名
#!/bin/bashfor i in {0..63}domysql -u$1 -p$2 -h127.0.0.1 <<EOFuse yoon;create table ivc_pre_de ...
- matlab实现插值法sin函数
插值法实现sin函数: %calculate and print the sine function %input: x %output: sin(x) similar function y = si ...
- ASP.NET Web – AJAX 回送
使用UpdatePanel时要一起使用的控件是ScriptManager.ScriptManager类加载了包含几个功能的JavaScript函数.也可以使用这个类加载自己定制脚本.ScriptMan ...
- 设置NODE_ENV=production
NodeJS - Express 4.0下设置环境变量NODE_ENV=production,并不是修改文件的配置信息,而是通过命令行来实现. 首先在命令行下进入项目的目录,然后先后执行如下命令: s ...
- 复习JS和jQuery
复习JS和jQuery 近些时日,以前学过的东西忘了好多.今天且写一点复习一下JS和jQuery.希冀与某年某月某日,忘却的时候,能看一下自己写的博文,尚可记起一二. 现在有需求如下:有两个按钮,一个 ...