A Bug's Life(削弱版食物链)
Description
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
interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
Output
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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=2005;
int par[maxn*2];
void init(int n)
{
for(int i=0; i<=n; i++)
par[i]=i;
}
int find(int x)
{
return par[x]==x?x:par[x]=find(par[x]);
}
void unite(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)return;
par[x]=y;
}
bool same(int x,int y)
{
return find(x)==find(y);
}
int main()
{
int T,tt=0,n,m;
scanf("%d",&T);
while(T--)
{
bool f=false;
scanf("%d%d",&n,&m);
init(n*2);
while(m--)
{
int x,y;
scanf("%d%d",&x,&y);
if(same(x,y)||same(x+n,y+n))
{
f=true;
}
else
{
unite(x,y+n);
unite(x+n,y);
}
}
printf("Scenario #%d:\n%s\n\n",++tt,f?"Suspicious bugs found!":"No suspicious bugs found!");
}
return 0;
}
A Bug's Life(削弱版食物链)的更多相关文章
- IE的CSS相关的BUG(整理一)
本来不想弄这个ie的bug的,真的很想让它快点死掉,可是事与愿违啊,没办法,还是贴出来,以备自用. 这个网页(http://haslayout.net/css/index)上例举了所有的IE和CSS相 ...
- QzzmServer v2.0正式版发布
V2.1升级程序已发布,具体见下文 首先,感谢网友的热情的测评及反馈,现Qzzm ...
- 洛谷1525 关押罪犯NOIP2010 并查集
问题描述 S城现有两座监狱,一共关押着N名罪犯,编号分别为1~N.他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨气值”(一个正整数值)来表示某两 ...
- CYQ.Data V4系列全面开源(2013-08-04)
致各位.NET开发者: 考虑到本人开源作品太多,个人维护力度有限,故自2013-08-04开始,开放原本需要授权使用的V4系列的最高版本V4.55的框架源码,同时也开放相对应的辅助工具源码,自此,V4 ...
- Apache HTTP Server 2.2.26 发布
Apache遗留产品线2.2.26发布.2013-11-13 之前的版本是2013-07-02的2.2.25 同样先在开发目录下放出下载,然后放到正式目录下.修正了大量的Bug.目前的稳定版2.4系列 ...
- 关于js运动的一些总结
js运动实现,有两种.一种是速度版,另一种是时间版. 速度版是通过对速度的加减乘除,得出元素的运动数据.时间版是通过对时间进行Tween公式运算,得出元素的运动数据. 速度版运动优点:容易在运动过程中 ...
- linux知识点
通过gui来使用通过api来使用通过cli来使用通过tui来使用 进程不在,但tcp连接还一直存在的解决办法--tcpkill命令 http://www.centoscn.com/CentOS/Int ...
- Hadoop2以来的历次升级(不含2.2.0及以下)
2015年7月06:release 2.7.1(稳定)请参阅 Hadoop 2.7.1发布说明 对131个bug修复和列表 从先前版本2.7.0补丁. 请看看 2.7.0章节列表的增强功能启用 第一个 ...
- iOS断点及打印日志
首先,最简单的断点就是在Xcode项目文件中任意一行行号那点一下,就是加了一个断点 再次点击会变成浅蓝色,表示disable掉了 disable掉的断点不会起作用,但会在左上角蓝色的标签那留下记录,这 ...
随机推荐
- 分布式锁-session-事务相关
1. 分布式锁--zookeeper 1). client调用create()方法创建"/root/lock_"节点,注意节点类型是EPHEMERAL_SEQUENTIAL. 2) ...
- java CyclicBarrier同步屏障
CyclicBarrier的字面意思是可循环使用的屏障,它的主要作用是,让一组线程到达一个屏障时被阻塞,知道最后一个线程到达屏障时,屏障才会打开,所有被屏障拦截的线程才会继续运行. 1.简介: Cyc ...
- <rhel6 mysql replication>
MySQL 支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环.这些日志可以记录发送到从服务 ...
- 使用WinSCP上传文件到linux系统
1.安装WinSCP 2.新建脚本test.txt option confirm off open username:password@host put C:\test\a.zip /home/tes ...
- KBEngine warring项目源码阅读(二) 登录和baseapp的负载均衡
原本不打算把登录拿出来写的,但是阅读登录部分的代码的时候发现登录和注册还不太一回事,因为登录涉及到分配baseapp的ip,负载均衡的实现,所以水一下. 流程图: 和上次一样,先是找unity控件 找 ...
- IO模型与soketserver实现并发
一 IO模型介绍 为了更好地了解IO模型,我们需要事先回顾下:同步.异步.阻塞.非阻塞 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非 ...
- js函数获取ev对象
今天工作中遇到一个问题,就是平时获取一个ev(event)对象时候一般直接在调用方法里面写一个ev参数,即可直接拿到这个对象,但是有时候会遇到函数调用不是直接加在一个dom对象的后面,如: var o ...
- OpenFirewall
1.写一份json文件:将要添加防火墙例外的应用程序和端口写入到json文件中 2.打开防火墙,读取json文件添加例外 /// <summary> /// Firewall.xaml 的 ...
- LAMP Stack 5.7.16 (Ubuntu 16.04.1)
平台: Ubuntu 类型: 虚拟机镜像 软件包: apache2.4 mysql5.7 php7 phpmyadmin4.5 apache application server basic soft ...
- C++ vector容器类型的用法及注意
转自http://www.cnblogs.com/charley_yang/archive/2010/12/11/1903040.html vector类为内置数组提供了一种替代表示,与string类 ...