(并查集)A Bug's Life -- POJ -- 2492
链接:
http://poj.org/problem?id=2492
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/J
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
using namespace std; #define N 10005 int f[N], r[N]; int Find(int x)
{
int k=f[x];
if(x!=f[x])
{
f[x]=Find(f[x]);
r[x]=(r[x]+r[k])%;
} return f[x];
} int main()
{
int i, t, n, m, k=;
scanf("%d", &t); while(t--)
{
int a, b, fa, fb, flag=;
scanf("%d%d", &n, &m); for(i=; i<=n; i++)
{
f[i]=i;
r[i]=;
} for(i=; i<m; i++)
{
scanf("%d%d", &a, &b);
fa=Find(a);
fb=Find(b);
if(fa!=fb)
{
f[fa]=fb;
r[fa]=(r[b]-r[a]+)%;
}
else
{
if(r[a]==r[b])
flag=;
} } printf("Scenario #%d:\n", k++);
if(flag)
printf("Suspicious bugs found!\n\n");
else
printf("No suspicious bugs found!\n\n");
} return ;
}
(并查集)A Bug's Life -- POJ -- 2492的更多相关文章
- A Bug's Life POJ - 2492 (带权并查集)
A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...
- A Bug’s Life POJ - 2492(种类并查集)
题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一 ...
- A Bug's Life POJ - 2492 (种类或带权并查集)
这个题目的写法有很多,用二分图染色也可以写,思路很好想,这里我们用关于并查集的两种写法来做. 题目大意:输入x,y表示x和y交配,然后判断是否有同性恋. 1 带权并查集: 我们可以用边的权值来表示一种 ...
- 并查集+关系的传递(poj 1182)
题目:食物链 题意:给定一些关系.判断关系的正确性,后给出的关系服从之前的关系: 思路:难点不在并查集,在于关系的判断,尤其是子节点与根节点的关系的判断: 这个关系看似没给出,但是给出子节点与父节点的 ...
- A Bug's Life POJ 2492
D - A Bug's Life 二分图 并查集 BackgroundProfessor Hopper is researching the sexual behavior of a rare spe ...
- POJ 2492 (简单并查集) A Bug's Life
题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...
- POJ 2492 并查集 A Bug's Life
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- (并查集 建立关系)Parity game -- POJ -1733
链接: http://poj.org/problem?id=1733 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
随机推荐
- unity 加载读取外部XML
cfg.xml <rootNode> <category name="网站"> <item name="mainPage"> ...
- Haskell语言学习笔记(52)正则表达式
Text.Regex.PCRE.Heavy $ brew install pcre $ cabal install pcre-heavy Installed pcre-heavy-1.0.0.2 Pr ...
- pyorient
简介 pyorient是orientdb的python库 该库提供两种访问orientdb的方式:1.client 的方式 2.ogm 的方式(类似于ORM) 由于OGM 封装了client,且由于O ...
- DNN例子
[Tensorflow DNNClassifier ValueError]http://stackoverflow.com/questions/40264622/tensorflow-dnnclass ...
- Manta
安装python客户端: pip install manta import manta as pymanta# cat ${MANTA_PRIVATE_KEY_PATH} | tr '\n' '#' ...
- Gviz
1) Introduction 为了理解基因组数据,通常旨在在基因组浏览器中绘制这样的数据,以及各种基因组注释特征,例如基因或转录物模型,CpG岛,重复区域等.这些功能可以从ENSEMBL或UCSC等 ...
- Spring Boot AOP
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是Spring框架中的一个重要内容,它通 ...
- sshd_config优化
sshd_config优化linux系统调优,参考百度搜索 linux ssh命令 /etc/init.d/sshd restart 重启ssh 193 ls 194 vim /e ...
- HashCode的理解
一.hashcode是什么 要理解hashcode首先要理解hash表这个概念 1. 哈希表 hash表也称散列表(Hash table),是根据关键码值(Key value)而直接进行访问的数据结构 ...
- 求含有n个因子的最小正整数(n<=1000000)
题目链接:https://ac.nowcoder.com/acm/contest/331/G 思路: 根据唯一分解定理,如果一个数n可以表示成 n=p1a1*p2a2*...*pkak (pi是第i个 ...