题目链接:传送门

题目大意:有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. Mac+docker+flask

    1.先要保证mac电脑安装docker 安装的话可以通过命令brew install docker 安装成功后启动,docker 然后在终端执行docker version 或者docker info ...

  2. nginx跨域(转2)

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...

  3. springboot学习(三) springboot文件配置

    1.简介 springboot没有了原来自己整合Spring应用时繁多的XML配置内容,替代它的是在pom.xml中引入模块化的Starter POMs,其中各个模块都有自己的默认配置,所以如果不是特 ...

  4. unity, UGUI Image shader

      Image组件的Material成员默认是空,如果想为Image添加shader,只需新建material赋给Material即可. 另外注意,用于UI组件的shader都要包含一句:ZTest  ...

  5. UVA 1262 Password 暴力枚举

    Password Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID:  ...

  6. Vivado 与 Modelsim 联合仿真

    1 编译库 用命令行 用vivado工具 vivado 有很多 IP核的接口 已经与 ISE的核 不太一样了,比如fir ,接口就是这样的: fir_lp fir_lp_ip(    .aclk  ( ...

  7. 严重: Error in dependencyCheck java.io.IOException: invalid header field(tomcat启动成功可是訪问web项目404错误)

    tomcat启动的时候出现 严重: Error in dependencyCheck java.io.IOException: invalid header field 而且tomcat也不自己主动r ...

  8. shell脚本之练习题

    设计一个shell程序,添加一个新组为class1,然后添加属于这个组的30个用户,用户名的形式为stdxx,其中xx从01到30. i=1 groupadd class1 while [ $i -l ...

  9. linux嵌入式大神的博客文章---持续更新中

    linux kernel子系统相关博客:http://www.wowotech.net/ 经典博文: http://blog.csdn.net/zqixiao_09 http://blog.china ...

  10. 如何在GitHub上删除某个文件夹?

    步骤: (以删除.idea文件夹为例) git rm -r --cached .idea #--cached不会把本地的.idea删除 git commit -m 'delete .idea dir' ...