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 ...
随机推荐
- SVN安装图解
SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上 ...
- ab测试
PS:网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个自带的,名为ab的程序,可以对Apache或其它类型的服务器进行网 ...
- 完整的站内搜索Demo(Lucene.Net+盘古分词)
前言 首先自问自答几个问题,以让各位看官了解写此文的目的 什么是站内搜索?与一般搜索的区别? 很多网站都有搜索功能,很多都是用SQL语句的Like实现的,但是Like无法做到模糊匹配(例如我搜索“.n ...
- struts2原理架构图
struts2 原理架构图
- Hadoop HDFS (3) JAVA訪问HDFS
如今我们来深入了解一下Hadoop的FileSystem类. 这个类是用来跟Hadoop的文件系统进行交互的.尽管我们这里主要是针对HDFS.可是我们还是应该让我们的代码仅仅使用抽象类FileSyst ...
- golang中channel的超时处理
并发中超时处理是必不可少的,golang没有提供直接的超时处理机制,但可以利用select机制来解决超时问题. func timeoutFunc() { //首先,实现并执行一个匿名的超时等待函数 t ...
- iOS 如何优雅的处理“回调地狱Callback hell”(一) (上)
前言 最近看了一些Swift关于封装异步操作过程的文章,比如RxSwift,RAC等等,因为回调地狱我自己也写过,很有感触,于是就翻出了Promise来研究学习一下.现将自己的一些收获分享一下,有错误 ...
- Android系统移植与驱动开发——第五章--搭建开发板的测试环境
开发板上安装嵌入式系统要比手机上简洁很多,有很多扩展的接口,适合对程序进行测试,这里所提及的是S3C6410开发板.它是由三星公司推出的一款低功耗/高性价比的RISC处理器.,其中包含强大的硬件加速器 ...
- 自己编写SqlHelper
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- ASP.NET数据报表之柱状图 ------工作日志
#region 柱形色调 /// <summary> /// 柱形色调 /// </summary> private string[] myColor = new string ...