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 ...
随机推荐
- WebSocket的原理与优缺点
websocket 是长连接,受网络限制比较大,需要处理好重连,比如用户进电梯或电信用户打个电话网断了,这时候就需要重连,如果 ws 一直重连不上,有些较复杂的业务方会不愿意的,是不是还要搞个 htt ...
- php Amome框架 层次设计备注
层次说明: 每一级中函数都是为而且只为 上(高)一层 的文件服务的 最底层: AmemoMySql 基础数据库函数:AmemoConfig 数据库信息配置文件 再高一层: 一个文件对应一个 ...
- 更改Ubuntu默认python版本的两种方法python-> Anaconda
当你安装 Debian Linux 时,安装过程有可能同时为你提供多个可用的 Python 版本,因此系统中会存在多个 Python 的可执行二进制文件.一般Ubuntu默认的Python版本都为2. ...
- 学以致用七---Centos7.2+python3.6.2+django2.1.1 --搭建一个网站(补充)
补充:上一节出现的报错提示 可在settings.py 里,改成 ‘*’ ,这样所有的主机都可以访问了. 打开网页 注意红色框出来的 hello 是和 urls.py里的hello对应 urls.p ...
- MySQL中@变量的妙用
背景需求:如下图所示,需要将下面为空的字段值,填充为第一行所示的值 第一次处理失败了 第二次使用成功 使用的SQL语句如下: set @tmp_var=''; select b.id,b.table_ ...
- GIS数据下载
WorldTile.hdf wuhan.hdf ... openstreetmap GIS空间数据库 分割存储. 检索效率有没有提高? 云地理服务:旅游,遥感数据处理,气温,地质,房价,人口,生活(商 ...
- android PendingIntent 使用通知传递多个参数,及不覆盖的问题
Intent updateIntent = new Intent(GetNoticeService.this, DetailGonggaoActivity.class); updateIntent.p ...
- springMVC:HandlerInterceptor拦截器的使用
1.使用背景 Web项目中需要判断http接口用户Post上来的数据是否合法,如果不合法要另做处理,用户Post上来的数据是Json形式的,我们用了@RequestBody标记自动将json形式的提交 ...
- Redis中在程序中的应用
1.导入redis的配置文件,因为要交给web容器管理,所以直接命名为ApplicationContext-redis.xml,具体配置如下: <beans xmlns="http:/ ...
- SRM468
250pt 给定手机0-9按键对应的英文字母(1个对多个),0固定对应空格.然后在给定一些单词.以及一个要处理的串,叫你按照那个串模拟输出结果 思路: 大模拟,写的有点乱 // BEGIN CUT H ...