加权并查集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. Android 自定义属性

    values新建一个attrs.xml<resource>    <declare-styleable name = "MyTextView">    &l ...

  2. php的数组与数据结构

    一.数组的分类与定义 分类: 1.索引数组  $array = array(1,2,3,4,5); 2.关联数组  $array=array(1=>"aa","bb ...

  3. MVP架构。。。。

    Model-View-Presenter(MVP)概述    MVC模式已经出现了几十年了,在GUI领域已经得到了广泛的应用,由于微软ASP.NET MVC Framework的出现,致使MVC一度成 ...

  4. list.clear()和list=null的区别

    以前并没有注意到list.clear()和list=null的区别,其实,区别在于 clear()方法是将list清空,但是对象的引用还在,只不过是一个表现为空引用 list=null是将list对象 ...

  5. servlet容器处理请求过程

    下图是关于tomcat服务器接收客户请求并作出响应的图例. tomcat不仅仅只是一个servlet容器,也是一个web服务器,servlet容器在web服务器之内或者说servlet容器托管于web ...

  6. linux基础命令学习(一)

    pwd 输出当前工作路径tree 以树状图列出目录的内容ctrl+c 取消命令的执行clear 清空屏幕ls 列出文件目录 蓝色是目录,白色是普通文件alias cls=clear 别名终端:本地终端 ...

  7. Python网络编程03----Python3.*中socketserver

    socketserver(在Python2.*中的是SocketServer模块)是标准库中一个高级别的模块.用于简化网络客户与服务器的实现(在前面使用socket的过程中,我们先设置了socket的 ...

  8. BZOJ 1912 巡逻

    重赋边权. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  9. iOS 微信 音频 视频自动播放

    iOS 微信 音频 视频自动播放 http://www.w3ctech.com/topic/1165

  10. Best Sequence_DFS&&KMp

    Description The twenty-first century is a biology-technology developing century. One of the most att ...