题目链接:传送门

题目大意:有n个昆虫,有m组关系,接下来m行表示两个昆虫性别不同,问是否有矛盾情况(同男同女)

题目思路:并查集的高级应用,开两倍数组大小,后n个数组表示和当前昆虫不同性别的集合

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define seg int root,int l,int r
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
#define Min(x,y) (x<y?x:y)
#define Max(x,y) (x>y?x:y)
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 100000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 10001000
typedef long long LL;
typedef pair<int,int> PII; int fp[N];
int findp(int x){return fp[x]==x?x:fp[x]=findp(fp[x]);} int main(){
int i,j,group,k,v,x,y,Case=,n,m;
scanf("%d",&group);
while(group--){
int flag=;
scanf("%d%d",&n,&m);
for(i=;i<=n<<;++i) fp[i]=i;
for(i=;i<m;++i){
scanf("%d%d",&x,&y);
if(!flag){
int xa=findp(x);
int ya=findp(y);
if(xa==ya) flag=;
else{
fp[xa]=findp(y+n);
fp[ya]=findp(x+n);
}
}
}
printf("Scenario #%d:\n",++Case);
if(flag) printf("Suspicious bugs found!\n\n");
else printf("No suspicious bugs found!\n\n");
}
return ;
}

hdu1829(A Bug's Life)的更多相关文章

  1. HDU-1829 A Bug's Life。并查集构造,与POJ1709异曲同工!

    A Bug's Life                                                     Find them, Catch them 都是并查集构造的题,不久前 ...

  2. hdu1829 A Bug&#39;s Life(并查集)

    开两个并查集.然后合并的时候要合并两次.这样在合并之前推断是否冲突,假设不冲突就进行合并,否则不须要继续合并. #include<cstdio> #include<cstdlib&g ...

  3. hdu1829 A Bug's Life 基础种类并查集

    题目的大意可以理解为:A爱B,B爱C ……给出一系列爱恋的关系,推断有没有同性恋. 思路是把相同性别的归为一个集合(等价类),异性的异性为同性. #include<iostream> #i ...

  4. poj1182、hdu1829(并查集)

    题目链接:http://poj.org/problem?id=1182 食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: ...

  5. A Bug's Life(hdu1829种类并查集)

    题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父 ...

  6. hdu1829&&poj2492 A Bug's Life 基础种类并查集

    把性别相同的虫子放在同一个集合,然后每读入一对虫子号,判断它们在不在同一集合,在则同性别,不在则继续 #include <cstdio> #include <cstring> ...

  7. POJ 2492 A Bug's Life【并查集高级应用+类似食物链】

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  8. Tomcat一个BUG造成CLOSE_WAIT

    之前应该提过,我们线上架构整体重新架设了,应用层面使用的是Spring Boot,前段日子因为一些第三方的原因,略有些匆忙的提前开始线上的内测了.然后运维发现了个问题,服务器的HTTPS端口有大量的C ...

  9. a标签点击跳转失效--IE6、7的奇葩bug

    一般运用a标签包含img去实现点击图片跳转的功能,这是前端经常要用到的东西. 今天遇到个神奇的bug:如果在img上再包裹一层div,而且div设置了width和height,则图片区域点击时,无任何 ...

随机推荐

  1. 常见的七大排序算法Java实现

    /** * @author Javen * @Email javenlife@126.com * 2015年12月9日 */ public class Sorting { static int[] a ...

  2. python abstractmethod 对象比较

    from functools import total_ordering from abc import ABCMeta,abstractmethod @total_ordering class Sh ...

  3. dubbo笔记

    使用Maven打包依赖项,启动时从本地jar中读取dubbo.xsd 最近项目用到dubbo,打包启动时报错 Failed to read schema document from http://co ...

  4. Easy Explore插件:在eclipse里快速打开文件所在的目录

    下载:easyexplore_1.0.4 安装:把文件”org.sf.easyexplore_1.0.4.jar”文件解压出来,然后复制到eclipse安装目录的”plugins”文件夹里 http: ...

  5. 构建基于Javascript的移动web CMS入门——简单介绍

    看到项目上的移动框架,网上寻找了一下,发现原来这些一開始都有. 于是,找了个演示样例開始构建一个移动平台的CMS--墨颀 CMS,方便项目深入理解的同一时候.也能够自己维护一个CMS系统. 构建框架 ...

  6. Android WebView 开发具体解释(三)

    转载请注明出处   http://blog.csdn.net/typename/article/details/40302351 powered by miechal zhao 概览 Android ...

  7. 使用swap 清空vector

    //最简单的使用swap,清除元素并回收内存 vector <int>().swap(vecInt); //清除容器并最小化它的容量, // vecInt.swap(vector<i ...

  8. webpack 打包压缩 ES6文件报错UglifyJs + Unexpected token punc ((); 或者 Unexpected token: operator (>)

    webpack 打包压缩 ES6文件报错UglifyJs + Unexpected token punc (();  或者 Unexpected token: operator (>) 解决方案 ...

  9. 一篇关于arc下内存管理的老文章,包含各种冷门修饰符(关于内存),写的较好,mark

    http://blog.csdn.net/zhibudefeng/article/details/7746201

  10. [ci]持续集成系列

    持续集成一直很蛋疼,感觉没底. 几个方面来写 1,搭建gitlab 配邮箱 域名等使之好用 2,搭建jenkins –yum,安装常见插件 3,搭建sonar,汉化 4,安装sonar-scanner ...