A Bug's Life

Time Limit: 10000MS Memory Limit: 65536K

Total Submissions: 28651 Accepted: 9331



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

TUD Programming Contest 2005, Darmstadt, Germany

/*********************************
author : Grant Yuan
time : 2014/10/5 11:29
algorithm: 并查集应用的扩展
source : POJ 2492
**********************************/
#include<iostream>
#include<cstdio>
#define MAX 2007
using namespace std;
int parent[MAX],relation[MAX];
int n,t,m;
int find_parent(int k)
{
if(k==parent[k])
return k;
int t=parent[k];
parent[k]=find_parent(parent[k]);
relation[k]=(relation[k]+relation[t]+1)%2;
return parent[k];
}
void unite(int a,int b)
{
int pa=find_parent(a);
int pb=find_parent(b);
parent[pa]=pb;
relation[pa]=(relation[b]-relation[a])%2;
}
int main()
{
scanf("%d",&t);
int ct=1;bool first=0;
while(t--){
bool ans=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
parent[i]=i,relation[i]=1;
for(int i=1;i<=m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
int pa=find_parent(a);
int pb=find_parent(b);
if(pa==pb){
if(relation[a]==relation[b]) ans=1;
}
else unite(a,b);
}
printf("Scenario #%d:\n",ct++);
if(ans) printf("Suspicious bugs found!\n\n");
else printf("No suspicious bugs found!\n\n");
}
return 0;
}

POJ 2492 并查集应用的扩展的更多相关文章

  1. POJ 2492 并查集扩展(判断同性恋问题)

    G - A Bug's Life Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  2. poj 2492 并查集

    思路:当a,b的根节点find(a)与find(b)不同时,就直接将这两个数连接起来.由于每个树的根节点的kind值一定为0,所以,对于a,b的kind值相同,我们就讲其中一个根的kind值变为1,当 ...

  3. POJ 2492 并查集 A Bug's Life

    #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> ...

  4. poj 1984 并查集

    题目意思是一个图中,只有上下左右四个方向的边.给出这样的一些边, 求任意指定的2个节点之间的距离. 就是看不懂,怎么破 /* POJ 1984 并查集 */ #include <stdio.h& ...

  5. poj 1797(并查集)

    http://poj.org/problem?id=1797 题意:就是从第一个城市运货到第n个城市,最多可以一次运多少货. 输入的意思分别为从哪个城市到哪个城市,以及这条路最多可以运多少货物. 思路 ...

  6. POJ 3228 [并查集]

    题目链接:[http://poj.org/problem?id=3228] 题意:给出n个村庄,每个村庄有金矿和仓库,然后给出m条边连接着这个村子.问题是把所有的金矿都移动到仓库里所要经过的路径的最大 ...

  7. poj 1733 并查集+hashmap

    题意:题目:有一个长度 已知的01串,给出多个条件,[l,r]这个区间中1的个数是奇数还是偶数,问前几个是正确的,没有矛盾 链接:点我 解题思路:hash离散化+并查集 首先我们不考虑离散化:s[x] ...

  8. poj 3310(并查集判环,图的连通性,树上最长直径路径标记)

    题目链接:http://poj.org/problem?id=3310 思路:首先是判断图的连通性,以及是否有环存在,这里我们可以用并查集判断,然后就是找2次dfs找树上最长直径了,并且对树上最长直径 ...

  9. POJ 3657 并查集

    题意: 思路: 1.二分+线段树(但是会TLE 本地测没有任何问题,但是POJ上就是会挂--) 2.二分+并查集 我搞了一下午+一晚上才搞出来----..(多半时间是在查错) 首先 如果我们想知道这头 ...

随机推荐

  1. JAVA对数据库进行操作,实现数据库中数据的插入,查询,更改,删除操作

    (—)通过mysql workbench 创建一个数据库,在这里命名为company,然后建一个tb_employee表 (二)以下是java代码对表tb_employee的操作 1 创建一个Empl ...

  2. Effective Java (7) - 避免终止方法

    一. 基本概念 1. 所谓的终结方法事实上是指finalize(). 2. Java的垃圾回收机制仅仅负责内存相关清理.其它资源的清理(释放文件.释放DB连接)须要程序猿手动完毕. 3. 调用Syst ...

  3. 学习json-rpc

    最近做一个和SmartHome相关的项目,文档不全不说,连个像样的Demo都没,痛苦!!当然,这是题外话.今天来说说项目中主要用到的通讯协议:json-rpc,简单地说,它是以json格式进行的远程调 ...

  4. WWDC 2014 Session 205/217 Extension 注意事项

    基于阅读下面的内容205和217的PDF做笔记.没有深入研究. 205 Creating Extensions for iOS and OS X, Part 1 217 Creating Extens ...

  5. jquery.validate.unobtrusive

    ASP.NET MVC Unobtrusive JavaScript 实现 onfocusout 验证, onfocusin 清除错误 在 ASP.NET MVC 中启用 Unobtrusive Ja ...

  6. velocity基本语法

    一.基本语法 1."#"用于识别Velocity该脚本语句,这包括#set.#if .#else.#end.#foreach.#end.#iinclude.#parse.#macr ...

  7. HDU1061-Rightmost Digit(高速功率模)

    pid=1061">主题链接 题意:求n^n的个位数的值. 思路:高速幂求值 代码: #include <iostream> #include <cstdio> ...

  8. SQLite外键

    数据库工具:SQLite Manager(V0.7.7) SQLite版本号:V3.6.19+ SQLite Manager 默认是不开启外键的. 那么怎样,使用它创建一个带有外键的表呢? 一.开启外 ...

  9. 打包静默安装参数(nsis,msi,InstallShield,InnoSetup)

    原文:打包静默安装参数(nsis,msi,InstallShield,InnoSetup)[转] 有时我们在安装程序的时候,希望是静默安装的,不显示下一步下一步,这编访问来教大家如何来操作,现在常用的 ...

  10. Deep Learning Papers

    一.Image Classification(Recognition) lenet: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf alexn ...