poj 2492A Bug's Life
http://poj.org/problem?id=2492
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define maxn 100010
int p[maxn],rela[maxn];
using namespace std;
int n,m;
void make()
{
for(int i=; i<=n; i++)
{
p[i]=i;
rela[i]=;
}
}
int find1(int x)
{
int temp=p[x];
if(x==p[x])
return x;
p[x]=find1(p[x]);
rela[x]=(rela[x]==rela[temp])?:;
return p[x];
}
void unionset(int x,int y,int px,int py)
{
p[px]=p[py];
rela[px]=(rela[x]==rela[y])?:;
}
int main()
{
int t,a,b;
scanf("%d",&t);
for(int i=; i<=t; i++)
{
scanf("%d%d",&n,&m);
bool flag=false;
memset(rela,,sizeof(rela));
make();
for(int j=; j<m; j++)
{
scanf("%d%d",&a,&b);
int fa=find1(a);
int fb=find1(b);
if(!flag){
if(fa==fb)
{
if(rela[a]==rela[b])
{
flag=true;
}
}
else
unionset(a,b,fa,fb);
}
}
printf("Scenario #%d:\n",i);
if(flag)
{ printf("Suspicious bugs found!\n\n");
}
else
printf("No suspicious bugs found!\n\n"); }
}
poj 2492A Bug's Life的更多相关文章
- poj 2492A Bug's Life(并查集)
/* 目大意:输入一个数t,表示测试组数.然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配. 要求统计交配过 ...
- POJ 1038 Bug Integrated Inc(状态压缩DP)
Description Bugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launchi ...
- 贪心 POJ 2586 Y2K Accounting Bug
题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...
- Poj 2586 / OpenJudge 2586 Y2K Accounting Bug
1.Link: http://poj.org/problem?id=2586 2.Content: Y2K Accounting Bug Time Limit: 1000MS Memory Lim ...
- poj 2586 Y2K Accounting Bug
http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...
- POJ 286 Y2K Accounting Bug【简单暴力】
链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...
- POJ 2856 Y2K Accounting Bug【简单暴力】
链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...
- A Bug's Life POJ - 2492 (带权并查集)
A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...
- POJ 2492 A Bug's Life
传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...
随机推荐
- webservice使用基本技巧
一,webService基本概念 webService也叫XMLWeb SerVice WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独 ...
- Android CountDownTimer 倒计时
摘自:http://www.cnblogs.com/over140/archive/2011/12/20/2294220.html 继承关系 public abstract class CountDo ...
- Eclipse中输入系统变量和运行参数--转
原文地址:http://chenzhou123520.iteye.com/blog/1931670 在开发时,有时候可能需要根据不同的环境设置不同的系统参数,我们都知道,在使用java -jar命令时 ...
- Creating a Navigation Drawer 创建一个导航侧边栏
The navigation drawer is a panel that displays the app’s main navigation options on the left edge of ...
- Sql Server插入随机数
--处理性别随机select (case when round(rand()*10,0)>5 then '男' else '女' end), --处理时间段范围内随机select dateadd ...
- 关于Jquery.Data()和HTML标签的data-*属性
人们总喜欢往HTML标签上添加自定义属性来存储和操作数据.但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它副 ...
- 使用Cxf发布Webservice服务,如果待发布的接口中有重载方法,怎么处理??
使用 @WebMethod(operationName="multiParamByName") 重新指定名字. http://bbs.csdn.net/topics/270059 ...
- Oracle 用户(user)和模式(schema)的区别
概述: (一)什么Oracle叫用户(user): A user is a name defined in the database that can connect to and access ob ...
- 六、C# 派生
派生 对一个现有的类型进行扩展,以便添加更多的功能,或者对现有的类型的操作进行重写. 比如可以将两个类都适用的方法和属性,用一个新的类进行重构,两个类再分别继承这个类. 定义一个派生类时,要在 ...
- JS中区分参数方法
实现功能:在使用cocosjs制作游戏过程中,很多东西都可以重复使用,例如菜单栏等等.今天尝试写了一个自定义的Js文件用作菜单方便以后使用. 将菜单按钮,以及触发事件作为参数生成一个层 直接在游戏中使 ...