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. 高效实现 std::string split() API

    Qt下一个 QString 实现split()性能.和std::string未实现它的.STL也未实现.只有自己可以写一. #include <string> #include <v ...

  2. codeforces 251A Points on Line(二分or单调队列)

    Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...

  3. jQuery绑定事件的四种基本方式

    Query中提供了四种事件监听方式,分别是bind.live.delegate.on,对应的解除监听的函数分别是unbind.die.undelegate.off. bind(type,[data], ...

  4. 用CSS3实现带小三角形的div框(不用图片)

    现在看到了很多带小三角形的方框,如微信.Mac版的QQ.QQ空间的时间轴等等,在聊天或者是发表的状态的内容外面都有一个带小三角形的矩形框包围着,感觉看着很不错,于是决定亲自动手写一个,我上次用的是偏移 ...

  5. JavaScript设计模式之观察者模式(学习笔记)

    设计模式(Design Pattern)对于软件开发来说其重要性不言而喻,代码可复用.可维护.可扩展一直都是软件工程中的追求!对于我一个学javascript的人来说,理解设计模式似乎有些困难,对仅切 ...

  6. MemCache缓存和C#自带的Cache缓存

    1.MemCache: //初始化 static SockIOPool _pool; // 创建Memcached private static MemcachedClient Create(stri ...

  7. Excel.Application手册

    ----转载:http://blog.csdn.net/xxfigo/article/details/6618129 定制模块行为(1) Option Explicit '强制对模块内所有变量进行声明 ...

  8. (转)php5中类的学习

    类的结构: 类的内部能可能有三种东西,就是常量(constant),属性(property)和方法(method),功能可以理解成类外部的常量,变量和函数.     复制代码代码如下: <?ph ...

  9. Google2016开发者大会

    Android主讲: 一.吴晶:android笔记博主(博客:http://www.race604.com/) 主题:Android低功耗蓝牙(BLE)实践 低功耗蓝牙在可穿戴和智能家居里边用的比较多 ...

  10. Swift - 17 - 数组的初始化

    import UIKit // 声明数组 var array = ["A", "B", "C", "D", " ...