链接:

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的更多相关文章

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

    A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...

  2. A Bug’s Life POJ - 2492(种类并查集)

    题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一 ...

  3. A Bug's Life POJ - 2492 (种类或带权并查集)

    这个题目的写法有很多,用二分图染色也可以写,思路很好想,这里我们用关于并查集的两种写法来做. 题目大意:输入x,y表示x和y交配,然后判断是否有同性恋. 1 带权并查集: 我们可以用边的权值来表示一种 ...

  4. 并查集+关系的传递(poj 1182)

    题目:食物链 题意:给定一些关系.判断关系的正确性,后给出的关系服从之前的关系: 思路:难点不在并查集,在于关系的判断,尤其是子节点与根节点的关系的判断: 这个关系看似没给出,但是给出子节点与父节点的 ...

  5. A Bug's Life POJ 2492

    D - A Bug's Life 二分图 并查集 BackgroundProfessor Hopper is researching the sexual behavior of a rare spe ...

  6. POJ 2492 (简单并查集) A Bug's Life

    题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...

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

    #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> ...

  8. 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733

    1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: ...

  9. (并查集 建立关系)Parity game -- POJ -1733

    链接: http://poj.org/problem?id=1733 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...

随机推荐

  1. 因为链接服务器 "SQLEHR" 的 OLE DB 访问接口 "SQLNCLI10" 无法启动分布式事务

    1.运行 regedt32,浏览至 HKEY_LOCAL_MACHINE\Software\Microsoft\MSDTC. 添加一个 DWORD 值 TurnOffRpcSecurity,值数据为 ...

  2. 作业:WordCount--实现字符数,单词数,行数的统计

    1. Gitee 地址 https://gitee.com/fyxiaobai/wordcount 2. PSP表格 PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟) Planning ...

  3. SVD 实现

    机器学习相关——SVD分解: http://www.cnblogs.com/luchen927/archive/2012/01/19/2321934.html SVD python实现: import ...

  4. 贝叶斯vs频率派:武功到底哪家强?| 说人话的统计学·协和八(转)

    回我们初次见识了统计学理论中的“独孤九剑”——贝叶斯统计学(戳这里回顾),它的起源便是大名鼎鼎的贝叶斯定理. 整个贝叶斯统计学的精髓可以用贝叶斯定理这一条式子来概括: 我们做数据分析,绝大多数情况下希 ...

  5. RNA-seq 安装 fastaqc,tophat,cuffilnks,hisat2

    ------------------------------------------ 安装fastqc------------------------------------------------- ...

  6. input radio 与label文字对齐

    input{ vertical-align:middle; margin-bottom:2px; *margin-bottom:2px; } 原地址

  7. Time range (447392) for take 'Take 001' is larger than maximum allowed(100000).

    http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html https://forum.unity3d.com/thr ...

  8. Python requests 使用心得

    最近在用requests写一些项目,遇见了一些问题,百度了很多,有些都不太好使,最后看了下requestsAPI文档,才明白了很多,最后项目趋于稳定.看来学东西还是API文档比较权威啊~ 问题场景 项 ...

  9. 6-Linux 上mysql的常用命令 以及 tomcat的相关指定

    mysql -u root -p 进入Mysql //注意一下有逗号!!! show databases; //显示所有的数据库 drop database mydb; // 删除mydb这个数据库 ...

  10. 生成静态页html

    代码: using System; using System.Collections; using System.Collections.Generic; using System.IO; using ...