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的更多相关文章

  1. poj 2492A Bug's Life(并查集)

    /* 目大意:输入一个数t,表示测试组数.然后每组第一行两个数字n,m,n表示有n只昆虫,编号从1—n,m表示下面要输入m行交配情况,每行两个整数,表示这两个编号的昆虫为异性,要交配. 要求统计交配过 ...

  2. POJ 1038 Bug Integrated Inc(状态压缩DP)

    Description Bugs Integrated, Inc. is a major manufacturer of advanced memory chips. They are launchi ...

  3. 贪心 POJ 2586 Y2K Accounting Bug

    题目地址:http://poj.org/problem?id=2586 /* 题意:某公司要统计全年盈利状况,对于每一个月来说,如果盈利则盈利S,如果亏空则亏空D. 公司每五个月进行一次统计,全年共统 ...

  4. 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 ...

  5. poj 2586 Y2K Accounting Bug

    http://poj.org/problem?id=2586 大意是一个公司在12个月中,或固定盈余s,或固定亏损d. 但记不得哪些月盈余,哪些月亏损,只能记得连续5个月的代数和总是亏损(<0为 ...

  6. POJ 286 Y2K Accounting Bug【简单暴力】

    链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...

  7. POJ 2856 Y2K Accounting Bug【简单暴力】

    链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...

  8. A Bug's Life POJ - 2492 (带权并查集)

    A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...

  9. POJ 2492 A Bug's Life

    传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...

随机推荐

  1. Git git rebase 使用

      原文:http://gitbook.liuhui998.com/4_2.html 一.基本 git rebase用于把一个分支的修改合并到当前分支. 假设你现在基于远程分支"origin ...

  2. UML学习之类图

    參考链接: http://www.uml.org.cn/oobject/201211231.asp  深入浅出UML http://www.open-open.com/lib/view/open132 ...

  3. 庖丁解牛FPPopover

    作者:ani_di 版权所有,转载务必保留此链接 http://blog.csdn.net/ani_di 庖丁解牛FPPopover FPPopover是一个实现Popover控件的开源项目,比标准控 ...

  4. Android(java)学习笔记246:ContentProvider使用之学习ContentProvider(内容提供者)的目的

    1.使用ContentProvider,把应用程序私有的数据暴露给别的应用程序,让别的应用程序完成对自己私有的数据库数据的增删改查的操作. 2.ContentProvider的应用场景: 获取手机系统 ...

  5. Linux基础系列—Linux内核源码目录结构

    /** ****************************************************************************** * @author    暴走的小 ...

  6. oracle中的function 、procedure、packages、package bodies比较

    1  function和procedure的区别 1).可以理解函数是存储过程的一种 2).函数可以没有参数,但是一定需要一个返回值,存储过程可以没有参数,不需要返回值 3).函数return返回值没 ...

  7. 不同浏览器创建XMLHttpRequest对象

    function getXHR() { if (XMLHttpRequest) { return new XMLHttpRequest(); } else { return new ActiveXOb ...

  8. MySQL 连接

    MySQL 连接 使用mysql二进制方式连接 您可以使用MySQL二进制方式进入到mysql命令提示符下来连接MySQL数据库. 实例 以下是从命令行中连接mysql服务器的简单实例: [root@ ...

  9. Mysql 源码编译教程贴

    题外话:这是一篇教程贴,不仅学的是mysql的编译,还是一些编译的知识.我也是一个菜鸟,写一些感悟和心得,有什么问题可以批评指正,谢谢! 如果只是为了安装请移到我的另一篇安装贴: Mysql安装贴 环 ...

  10. 安装 php

    1.yum安装php yum install php 2.配置 apache 支持 php a.找到httpd.conf find / -name  httpd.conf b.编辑 httpd.con ...