Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

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. 

#include<iostream>
#include<cstdio> using namespace std; #define N 2010 int f[N], v[N]; // v 数组存的是下标与其根结点的性别状态,0代表同性,1代表异性,f存的是下标的根结点 int found(int x)
{
int k = f[x]; if(f[x] != x)
{
f[x] = found(k); // 寻找根结点
v[x] = (v[x]+v[k])%; // 根结点在变,v数组其与根结点的状态也要变,如果与其原先
}
return f[x];
}
int main()
{
int t, a, b, n, m; cin >> t; for(int i = ; i <= t; i++)
{
cin >> n >> m;
int ok = ; for(int j = ; j <= n; j++)
f[j] = j, v[j] = ; while(m--)
{
cin >> a >> b; if(ok) continue; int na = found(a), nb = found(b); if(na == nb && (v[a]+)% != v[b]) // 如果两个数之前已经有了联系,并且联系不是正常的,同性恋(相等代表正常,ok置为1,就有可疑对象发现
ok = ;
if(na != nb)
{
f[na] = nb; v[na] = (-v[a]+v[b])%; // 如果之前两个没有联系,就把两个数的根结点联系起来(根据已知其与根结点状态~
}
}
if(i != )
printf("\n");
printf("Scenario #%d:\n", i);
if(ok)
printf("Suspicious bugs found!\n");
else
printf("No suspicious bugs found!\n");
}
printf("\n"); // 格式控制,虽然我也没看见题上哪句话是这意思
return ;
}

之前一直不太懂什么意思,什么算同性恋,是opposite gender?醉了,是与当前已知条件矛盾。一个人和另一个人有关系就在一个树上,有点关系的都在一条树上。一棵树上应该与根结点状态一致,否则就是同性恋,不在一棵树上随便状态。。和食物链是不是一样,但是我根本都没想食物链的事。。

头脑简单四肢发达的生物,想不出来一直想~

A Bug's Life - poj2492的更多相关文章

  1. J - A Bug's Life - poj2492

    这个题目很有意思啊,有一些bug生物(肯定是程序员养的),有人观察他们的生活习惯,观察他们之间是否有同性恋关系,比如ab发生关系,bc发生关系,ab发生关系...产生了同性恋了,你需要判断一下这种关系 ...

  2. [poj2492]A Bug's Life(并查集+补集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 34678   Accepted: 11339 D ...

  3. POJ2492 A Bug's Life

    Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 33833   Accepted: 11078 Description Ba ...

  4. poj2492 A Bug's Life【并查集】

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

  5. poj2492 A Bug's Life(带权并查集)

    题目链接 http://poj.org/problem?id=2492 题意 虫子有两种性别,有n只虫子,编号1~n,输入m组数据,每组数据包含a.b两只虫子,表示a.b为不同性别的虫子,根据输入的m ...

  6. POJ2492:A Bug's Life(种类并查集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 45757   Accepted: 14757 题 ...

  7. POJ2492 A Bug's Life —— 种类并查集

    题目链接:http://poj.org/problem?id=2492 A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Su ...

  8. POJ2492 A Bug's Life 带权并查集

    分析:所谓带权并查集,就是比朴素的并查集多了一个数组,记录一些东西,例如到根的距离,或者和根的关系等 这个题,权数组为relation 代表的关系  1 和父节点不同性别,0,和父节点同性别 并查集一 ...

  9. poj2492 A Bug's Life【基础种类并查集】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298148.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

随机推荐

  1. 高级软件工程第二次作业:随机生成N个不重复的已解答完毕的数独棋盘

    #include <stdio.h> #include "SuduCheck.h" ][],int i,int j,int k) //判断是否可以将第i行.第j列的数设 ...

  2. final、以及public、protected、(default)、private权限修饰符总结

    package cn.learn.Final; /* 当final用来修饰类 1.该类不能有任何子类,成员方法均无法覆盖重写,但可以重写父类的方法 当final用来修饰方法 1.该方法不能被覆盖重写 ...

  3. exports、module.exports和export、export default到底是咋回事

    地址1:https://segmentfault.com/a/1190000010426778 地址2:https://blog.csdn.net/caixiaowang/article/detail ...

  4. 断路器,AOP实现断路器模式 ------------Hystrix

    断路器:https://martinfowler.com/bliki/CircutiBreaker.html 核心思想: 在断路器对象中封装受保护的方法调用. 该断路器监控调用和断路情况 调用失败触发 ...

  5. BZOJ 4821 (luogu 3707)(全网最简洁的代码实现之一)

    题面 传送门 分析 计算的部分其他博客已经写的很清楚了,本博客主要提供一个简洁的实现方法 尤其是pushdown函数写得很简洁 代码 #include<iostream> #include ...

  6. luoguP3384 [模板]树链剖分

    luogu P3384 [模板]树链剖分 题目 #include<iostream> #include<cstdlib> #include<cstdio> #inc ...

  7. python最新字符串学习总结

    names="hello word" len() title() formate 格式化 split join find() replace() startswith() ends ...

  8. SQL server2000 创建表单的方法(已实践检验)

    我的系统是win7旗舰版的,在安装完SQL server2000之后,单击表,右键-新建表时,系统要么弹出:MMC检测到此管理单元发生一个错误.要么直接弹出microsoft sql server 2 ...

  9. JavaScript中函数带与不带括号的区别

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. java 进销存 商户管理 系统 管理 库存管理 销售报表springmvc SSM项目

    统介绍: 1.系统采用主流的 SSM 框架 jsp JSTL bootstrap html5 (PC浏览器使用) 2.springmvc +spring4.3.7+ mybaits3.3  SSM 普 ...