加权并查集mod2模板 本体的难点是bug的释义(笑)

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std; int father[],sum[];
int find(int x)
{
if(father[x] != x) {
int tmp = father[x];
father[x] = find(tmp);
sum[x] = (sum[x] + sum[tmp]) % ;
}
return father[x];
}
void merge(int x,int y)
{
int tx = find(x);
int ty = find(y);
//printf("x = %d y = %d\ntx = %d ty = %d\n", x, y, tx, ty);
if(tx == ty) return;
father[tx] = ty;
//printf("father(1) = %d\n",father[1]);
sum[tx] = (sum[x] - sum[y] + ) % ;
return;
}
int main()
{
int t;
scanf("%d",&t);
for(int kase = ; kase <= t; kase++)
{
int n, m;
bool flag = true;
scanf("%d%d", &n, &m);
//Initiate
for(int i = ; i <= n; i++)
{
father[i] = i;
sum[i] = ;
}
while(m--)
{
int a, b;
scanf("%d%d", &a, &b);
if(find(a) == find(b))
{
if(sum[a] != (sum[b] + ) % ){
//printf("a = %d b = %d\n", a, b);
flag = false;
}
}
else
merge(a, b);
}
printf("Scenario #%d:\n", kase);
if(flag) printf("No suspicious bugs found!\n\n");
else printf("Suspicious bugs found!\n\n");
}
return ;
}

kuangbin_UnionFind J (POJ 2492)的更多相关文章

  1. POJ 2492 并查集扩展(判断同性恋问题)

    G - A Bug's Life Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u S ...

  2. POJ 2492 并查集应用的扩展

    A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 28651 Accepted: 9331 Descri ...

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

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

  4. 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条臭 ...

  5. (并查集)A Bug's Life -- POJ -- 2492

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

  6. kuangbin_ShortPath J (POJ 1511)

    其实虽然一开始有被这个题的8000MS 和 256MB限制又被吓到 但是严格来说跟之前的POJ 3268是一样的做法只是数据大了点 但是问题就出在数据大了点上 其实严格来说也不大 1e6 数组加起来大 ...

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

    http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...

  8. poj 2492(关系并查集) 同性恋

    题目;http://poj.org/problem?id=2492 卧槽很前卫的题意啊,感觉节操都碎了, t组测试数据,然后n,m,n条虫子,然后m行,每行两个数代表a和b有性行为(默认既然能这样就代 ...

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

    题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...

随机推荐

  1. SharePoint 2013 开发——开发并部署Provider-hosted APP

    博客地址:http://blog.csdn.net/FoxDave 本篇我们用Visual Studio创建并部署一个SharePoint Provider-hosted应用程序. 打开Visua ...

  2. 管理Fragment

    转载原地址:http://blog.csdn.net/harvic880925/article/details/44927375 相关文章: 1.<Fragment详解之一——概述>2.& ...

  3. Cocoa Drawing

    Graphics Contexts Graphics contexts are a fundamental part of the drawing infrastructure in Cocoa ap ...

  4. IT人才最容易犯的17个错误--人生警言

    转载 记得刚参加工作时(那是97年),中国的IT刚刚兴起,那时,作为一个IT人士是一件很光荣的事,而那时的我正在做电气和电子相关的工作.99年第一次跳槽,进入了IT行业做软件开发.至今,中国的IT已经 ...

  5. GSM BTS Hacking: 利用BladeRF和开源BTS 5搭建基站

    引文 如果你已经购买了Nuand(官方)BladeRF x40,那么就可以在上面运行OpenBTS并可以输入一些指令来完成一些任务.一般来说HackRF,是一款覆盖频率最宽的SDR板卡.它几乎所有的信 ...

  6. 使用copy来拷贝对象

    拷贝对象 您通过将 copy 消息发送给对象,以制作对象的副本. NSArray *myArray = [yourArray copy]; 要拷贝,接收对象的类必须遵守 NSCopying 协议.如果 ...

  7. 数据结构 《5》----二叉搜索树 ( Binary Search Tree )

    二叉树的一个重要应用就是查找. 二叉搜索树 满足如下的性质: 左子树的关键字 < 节点的关键字 < 右子树的关键字 1. Find(x) 有了上述的性质后,我们就可以像二分查找那样查找给定 ...

  8. HDOJ-三部曲-多重背包-1014-Cash Machine

    通过这道题我基本了解了利用二进制对多重背包问题进行优化的思想. Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submiss ...

  9. 作业1-我的第一个博客&GuiHub简单练习

    自我介绍                   姓名:苗中峰(不要问有什么含义,翻着字典取的名,翻到什么字就取了什么字)                               性别:男(不解释) ...

  10. .NET的语法优化

    1.多参数 判断 条件 //判断 var fileKey = new { DateStart = search.DateStart.IsNull(), //关开始时间 DateEnd = search ...