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 ...
随机推荐
- 菜品识别 API调用
#get_access_token.py #获取access_token 1 import requests def GetToken(API_KEY,SECRET_KEY): url = 'http ...
- querySelectorAll()方法
querySelectorAll()方法 调用的对象包括:Document(文档) DocumentFragment(文档片段) Element(元素) querySelectorAll()方法接收的 ...
- tinyweb集成springmvc 的一种可行方式
最近tiny项目中集成了springmvc,而且使用的tiny的版本比较低,所以整合起来官网给的前两种方式都行不通. 而且有个tiny整合springmvc的maven依赖都下载不了.所以只有使用第三 ...
- WEB上传大文件解决方案
众所皆知,web上传大文件,一直是一个痛.上传文件大小限制,页面响应时间超时.这些都是web开发所必须直面的. 本文给出的解决方案是:前端实现数据流分片长传,后面接收完毕后合并文件的思路.下面贴出简易 ...
- Spring 整合 RocketMQ
1. 引入jar包 <!-- RocketMQ --> <dependency> <groupId>com.alibaba.rocketmq</groupId ...
- VHDL基础2
Signals & Variables VHDL 提供了 signal 和 variable 两种对象来处理非静态数据:提供了 constant 和 generic 来处理静态数据. cons ...
- C++之const限定符(顶层const,底层const)
作者:tongqingliu 转载请注明出处:http://www.cnblogs.com/liutongqing/p/7050815.html C++之const限定符(顶层const,底层cons ...
- 位图bitbucket
问题:假设有500w条数据,数据是在2^32-1的范围内,数据重复,如何减少内存对数字进行统计呢? 如果用字典来标记数字是否已经统计过来,数字做为key, value仅为0 or1,那么这样需要消耗 ...
- (动态规划)matrix -- hdu -- 5569
http://acm.hdu.edu.cn/showproblem.php?pid=5569 matrix Time Limit: 6000/3000 MS (Java/Others) Memo ...
- 通过domoticz restful接口更新数据 c# 控制台程序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...