题面

这道题是一道标准的种类并查集:

种类并查集是给每个结点一个权值。然后在合并和查找的时候根据情况对权值来进行维护。

通过将原有的区间范围变大使并查集可以维护种类的联系:

#include <iostream>
#include <cstdio>
using namespace std;
int f[];
int zhaobaba(int x)
{
if(f[x]==x) return x;
return f[x]=zhaobaba(f[x]);
}
int main()
{
int T;
cin>>T;
int t=T;
while(t--){
int n,m;
cin>>n>>m;
for(int i=;i<=*n;i++) f[i]=i;
bool lala=;
for(int i=;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
if(lala) continue;
if(zhaobaba(u)==zhaobaba(v)){
lala=;
continue;
}
f[zhaobaba(u)]=zhaobaba(v+n);
f[zhaobaba(u+n)]=zhaobaba(v);
}
cout<<"Scenario #"<<T-t<<":"<<endl;
if(!lala){
cout<<"No suspicious bugs found!"<<endl;
}
else{
cout<<"Suspicious bugs found!"<<endl;
}
cout<<endl;
}
}

POJ 2492 A Bug's Life 题解的更多相关文章

  1. hdu - 1829 A Bug's Life (并查集)&&poj - 2492 A Bug's Life && poj 1703 Find them, Catch them

    http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...

  2. POJ 2492 A Bug's Life(并查集)

    http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...

  3. (简单) POJ 2492 A Bug's Life,二分染色。

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

  4. POJ 2492 A Bug's Life (并查集)

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

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

    题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...

  6. POJ 2492 A Bug's Life

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

  7. POJ 2492 A Bug's Life (并查集)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 30130   Accepted: 9869 De ...

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

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

  9. hdu 1829 &amp;poj 2492 A Bug&#39;s Life(推断二分图、带权并查集)

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

随机推荐

  1. jquery dblclick()方法 语法

    jquery dblclick()方法 语法 作用:当双击元素时,会发生 dblclick 事件.当鼠标指针停留在元素上方,然后按下并松开鼠标左键时,就会发生一次 click.在很短的时间内发生两次 ...

  2. luoguP1468 派对灯 Party Lamps x

    P1468 派对灯 Party Lamps 题目描述 在IOI98的节日宴会上,我们有N(10<=N<=100)盏彩色灯,他们分别从1到N被标上号码. 这些灯都连接到四个按钮: 按钮1:当 ...

  3. 动态调用WebService接口的几种方式

    一.什么是WebService? 这里就不再赘述了,想要了解的====>传送门 二.为什么要动态调用WebService接口? 一般在C#开发中调用webService服务中的接口都是通过引用过 ...

  4. python实现的一个中文文本摘要程序

    文本摘要方法有很多,主要分为抽取式和生成式,应用比较多的是抽取式,也比较简单,就是从文本中抽取重要的句子或段落.本方法主要是利用句子中的关键词的距离,主要思想和参考来自阮一峰的网络日志http://w ...

  5. python27 错误汇总

    一.TypeError: object of type 'NoneType' has no len() 解决的方法: 源代码:resp_data = None  (None是一个空的对象) 修改后代码 ...

  6. C++入门经典-例4.5-利用循环求n的阶乘

    1:代码如下: // 4.5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...

  7. 第九周课程总结 & 实验报告(七)

    第九周课程总结 一.多线程 1.线程的状态 2.线程操作的相关方法 二.Java IO 1.操作文件的类---File ()基本介绍 ()使用File类操作文件 .RandomAccessFile类 ...

  8. docker —宝塔面板

    下载个单独的系统镜像 [root@git opt]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx-tomcat ...

  9. VS2017 -error LNK1104: 无法打开文件“msvcprtd.lib”

    原文地址:https://blog.csdn.net/u012308586/article/details/89309495 VS2017 -error LNK1104 无法打开文件“msvcprtd ...

  10. Linux命令之grep用法详解:grep与正则表达式 [转]

    正则表达式与通配符不一样,它们表示的含义并不相同. grep命令的选项用于对搜索过程进行补充说明.grep命令的模式十分灵活,可以是字符串.变量,还可以是正则表达式. 无论模式是何种形式,只要模式中包 ...