POJ 2492
#include<iostream>
#include<stdio.h>
#define MAXN 2050
using namespace std; int pre[MAXN];
int opp[MAXN]; void init(int n)
{
int i;
for(i = ; i <= n; ++ i)
{
pre[i] = i;
opp[i] = -;
}
} int find_pre(int x)
{
if(pre[x] != x)
{
pre[x] = find_pre(pre[x]);
}
return pre[x];
} int comb(int x,int y)
{
if(x == -)
return y;
if(y == -)
return x;
pre[x] = y;
return y;
} int main()
{
//freopen("acm.acm","r",stdin);
int test;
int n;
int m;
int i;
int u;
int v;
int temp1;
int temp2;
bool boo;
bool bo;
int k;
scanf("%d",&test);
for(k = ; k < test; ++ k)
{
scanf("%d%d",&n,&m);
init(n);
boo = false; cout<<"Scenario #"<<k+<<":"<<endl;
for(i = ; i < m; ++ i)
{
bo = false;
scanf("%d%d",&u,&v);
temp1 = u;
temp2 = v;
if(i != )
{
temp1 = find_pre(temp1);
temp2 = find_pre(temp2);
if(temp1 == temp2)
{
boo = true;
// bo = true;
}
}
if(!boo)
{
u = find_pre(u);
v = find_pre(v);
temp1 = comb(u,opp[v]);
temp2 = comb(opp[u],v);
opp[temp1] = temp2;
opp[temp2] = temp1;
}
}
if(boo)
{
cout<<"Suspicious bugs found!"<<endl;
}
else
{
cout<<"No suspicious bugs found!"<<endl;
}
cout<<endl;
}
}
POJ 2492的更多相关文章
- POJ 2492 并查集扩展(判断同性恋问题)
G - A Bug's Life Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u S ...
- POJ 2492 并查集应用的扩展
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28651 Accepted: 9331 Descri ...
- A Bug's Life POJ - 2492 (带权并查集)
A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...
- 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条臭 ...
- POJ 2492 A Bug's Life(并查集)
http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...
- poj 2492(关系并查集) 同性恋
题目;http://poj.org/problem?id=2492 卧槽很前卫的题意啊,感觉节操都碎了, t组测试数据,然后n,m,n条虫子,然后m行,每行两个数代表a和b有性行为(默认既然能这样就代 ...
- (并查集)A Bug's Life -- POJ -- 2492
链接: http://poj.org/problem?id=2492 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- POJ 2492 A Bug's Life(带权并查集)
题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...
- POJ 2492 (简单并查集) A Bug's Life
题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...
- (简单) POJ 2492 A Bug's Life,二分染色。
Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs ...
随机推荐
- WPF编程宝典(Pro wpf in c# 2012)(文摘)
第一部分 基础知识 第1章 WPF概述 第2章 XAML 第3章 布局 第4章 依赖项属性 第5章 路由事件 第二部分 进一步研究WPF 第6章 控件 第7章 Application类 第8章 元素绑 ...
- Java数组的初始化
1.动态初始化 数据类型 [] 变量名 = new 数据类型 [数组大小]; //数组的动态初始化 int [] arr = new int [3]; 2.静态初始化 数据类型 [] 变量名 = {元 ...
- Linux centos 连接网络
1.在安装过程中不要选择网络适配器,其他正常执行 2.编辑 [root@zb ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 一般安装完软件,打开et ...
- HTTP请求模型和头信息参考
发送HTTP请求:一个请求由四个部分组成:请求行.请求头标.空行和请求数据 请求行 请求行由三个标记组成:请求方法.请求URI和HTTP版本,它们用空格分隔.例如:GET /index.html HT ...
- 【慕课网实战】Spark Streaming实时流处理项目实战笔记九之铭文升级版
铭文一级: 核心概念:StreamingContext def this(sparkContext: SparkContext, batchDuration: Duration) = { this(s ...
- 1.9yield方法
yield()方法的作用放弃当前的cpu资源,将他让给其他的任务去占用cpu的执行时间,但放弃的时间不确定,有可能刚放弃,马上又获得cpu时间片 测试 package com.cky.thread; ...
- 通过request获取网页资讯 通过BeautifulSoup剖析网页元素
import requests newsUrl ='http://news.sina.com.cn/china/' res = requests.get(newsUrl) res.encoding ...
- 微软新一代Surface,该怎么看?
近日,微软在美国纽约发布了其全新一代产品——Surface 2和Surface Pro 2.如果留意微软官方商城的话,可以看到该产品现已全面开放预购.那么,这样一款产品到底怎么样?让我们来一个横向的对 ...
- java中三种注释
//单行注释 /* 多行注释 */ /** * 文档注释 * version 2018.10.25 * authou GMY */
- redis-master/slave模式
类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...