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 ...
随机推荐
- Android中的RelativeLayout
安卓布局之一,RelativeLayout.又称之为相对布局.对于一个界面每个人都有不同的实现.我比较喜欢使用RelativeLayou.原因是,相对布局不会出现过多的嵌套,在现在硬件不断发展的今天, ...
- Mybatis+SpringMVC实现分页查询(附源码)
Maven+Mybatis+Spring+SpringMVC实现分页查询(附源码) 一.项目搭建 关于项目搭建,小宝鸽以前写过一篇Spirng+SpringMVC+Maven+Mybatis+MySQ ...
- [转]Android实现计时与倒计时(限时抢购)的几种方法
在购物网站的促销活动中一般都有倒计时限制购物时间或者折扣的时间,这些都是如何实现的呢? 在一个安卓客户端项目中恰好遇到了类似的问题,一开始使用的是Timer与 TimerTask, 虽然此方法通用,但 ...
- SAP-MM:收货转储时提示 M7053“只能在公司代码 **** 的期间 2014/04 和 2014/03 中记账”
错误信息 消息号M7053 解决方法 Step 1.使用MMPV进入"关闭账期"界面. Step 2.输入"公司代码"."期间".& ...
- Linux(SLES)挂载NTFS移动硬盘实践
问题描写叙述: 因为通过測试环境导出的dmp过大,但要求尽快导入至生产server,请网络室打通防火墙后发现測试网络为100M而生产网络贵为1000M却无法发挥不论什么作用即使通过networklin ...
- Swoole源代码学习记录(十五)——Timer模块分析
swoole版本号:1.7.7-stable Github地址:点此查看 1.Timer 1.1.swTimer_interval_node 声明: // swoole.h 1045-1050h ty ...
- python 参议院文本预处理的一维数组的间隔空间
#!/usr/bin/python import re def pre_process_msg ( msgIn ): if msgIn=="": retur ...
- 代码讲解Android Scroller、VelocityTracker
在编写自定义滑动控件时常常会用到Android触摸机制和Scroller及VelocityTracker.Android Touch系统简介(二):实例详解onInterceptTouchEvent与 ...
- 使用ssh对服务器进行登录
一.什么是SSH? 简单说,SSH是一种网络协议,用于计算机之间的加密登录. 如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登录是安全的,即使被中途截获,密码也不会 ...
- My.Ioc 的性能
IoC/DI 这个概念,最初是由 Martin Fowler 提出来的.之后,很快在 Java 社区大行其道.在 .net 社区,IoC 的流行要比 Java 晚一些.尽管如此,现在开源社区中也已经出 ...