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

Problem Description
Background 
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.

 
Input
The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
 
Output
The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.
 
Sample Input
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
 
Sample Output
 
Scenario #1:
Suspicious bugs found!
 
Scenario#2:
No suspicious bugs found!
 
Hint

Huge input,scanf is recommended.

Source
 #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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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条臭 ...

  4. 【进阶——种类并查集】hdu 1829 A Bug's Life (基础种类并查集)TUD Programming Contest 2005, Darmstadt, Germany

    先说说种类并查集吧. 种类并查集是并查集的一种.但是,种类并查集中的数据是分若干类的.具体属于哪一类,有多少类,都要视具体情况而定.当然属于哪一类,要再开一个数组来储存.所以,种类并查集一般有两个数组 ...

  5. hdu 1829 A Bug's Life(并查集)

                                                                                                    A Bu ...

  6. HDU 1829 - A Bug's Life

    Problem Description Background Professor Hopper is researching the sexual behavior of a rare species ...

  7. HDU 1829 A Bug's Life 【带权并查集/补集法/向量法】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  8. hdoj 1829 A bug's life 种类并查集

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 并查集的一个应用,就是检测是否存在矛盾,就是两个不该相交的集合有了交集.本题就是这样,一种虫子有 ...

  9. HDU 1829 A Bug's Life(种类并查集)

    思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...

随机推荐

  1. wordpress忘记密码重置

    一直使用浏览器记录密码的方式登陆wordpress,直到有一天重装系统,而浏览器的记录又没有备份,结果怎么也想不起当初所设定的密码了…… -_-||| 遂google了一番,发现了直接修改数据库重设密 ...

  2. Qt for Android 程序禁止屏幕旋转

    有时候我们希望让一个程序的界面始终保持在一个方向,不随手机(平板)方向旋转而变化:在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screen ...

  3. [sql server] 如何阻止SELECT * 语句

    我们每个人都知道是个不好的做法,但有时我们还是要这样做:我们执行SELECT * 语句.这个方法有很多弊端: 你从你的表里返回每个列,甚至后期加的列.想下如果你的查询里将来加上了VARCHAR(MAX ...

  4. jquery如何通过name名称获取当前name的value值

    本文为大家介绍下jquery通过name名称获取当前name的value值的具体实现,感兴趣的朋友可以参考下. 复制代码代码如下: $("*[name='name']").val( ...

  5. Oracle 表的访问方式(2)-----索引扫描

    索引扫描(Index scan) 我们先通过index查找到数据对应的rowid值(对于非唯一索引可能返回多个rowid值),然后根据rowid直接从表中得到具体的数据,这种查找方式称为索引扫描或索引 ...

  6. Microsoft Visual Studio Ultimate 2015 Preview使用笔记

    1.内存好象存在泄露问题

  7. 自改xss小平台上线

    原先一直用xss.hk结果不知怎么被关的,正好手上有代码于是自己搭了一个,网上的类似的xss平台大多一样,原先的xss的chrome插件,不适合 "manifest_version" ...

  8. 安装mysql 5.5.14 报错

    提示cmake nod foundyum install cmake 原因是曾经服务器安装过mysql数据库Installing MySQL system tables...101223 14:28: ...

  9. Android手机做无线中继路由器

    为什么要拿手机做路由器?因为我现在每天要带着一个火柴盒大小的路由器(703n).它提供了一个f了q的无线网络,电脑,手机,平板等设备连接上这个无线网络之后之后就可以自由上twitter,看youtub ...

  10. C#TCPClient应用-一个简单的消息发送和接收

    TcpSend窗口用于发送消息,另外写一个用于接收消息的应用程序,消息接受到以后,必须要关闭接收消息的窗口,才能在接收新的消息,不知道怎么能解决这个问题. 源代码: 发送消息的窗口代码 using S ...