kuangbin_UnionFind J (POJ 2492)
加权并查集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)的更多相关文章
- 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条臭 ...
- (并查集)A Bug's Life -- POJ -- 2492
链接: http://poj.org/problem?id=2492 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
- kuangbin_ShortPath J (POJ 1511)
其实虽然一开始有被这个题的8000MS 和 256MB限制又被吓到 但是严格来说跟之前的POJ 3268是一样的做法只是数据大了点 但是问题就出在数据大了点上 其实严格来说也不大 1e6 数组加起来大 ...
- 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有性行为(默认既然能这样就代 ...
- POJ 2492 A Bug's Life(带权并查集)
题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...
随机推荐
- Keil 4.0 生成bin文件
在菜单:Flash /configuare falsh tools ... option for Tatget '项目' /User中:在Run User Programs After Build/R ...
- @ModelAttribute注解的作用
@ModelAttribute注解的作用:1.放在方法上注解不带属性: 方法无返回值: 执行其他方法时,先执行该注解标记方法. 如果方法中有将一些属性放入model的操作,其他方法model中也会共享 ...
- 介绍NSURLSession网络请求套件
昨天翻译了一篇<NSURLSession的使用>的文章,地址:http://www.cnblogs.com/JackieHoo/p/4995733.html,原文是来自苹果官方介绍NSUR ...
- Notification通知栏
Notification通知栏 首先实现的功能就是通知栏显示Notification,Notification是显示在系统的通知栏上面的,所以Notification 是属于进程之前的通讯.进程之间的 ...
- Ubuntu 14.10 下安装Ganglia监控集群
关于 Ganglia 软件,Ganglia是一个跨平台可扩展的,高性能计算系统下的分布式监控系统,如集群和网格.它是基于分层设计,它使用广泛的技术,如XML数据代表,便携数据传输,RRDtool用于数 ...
- Matlab单一变量曲线拟合-cftool
2.启动曲线拟合工具箱>cftool 3.进入曲线拟合工具箱界面“Curve Fitting tool”(1)点击“Data”按钮,弹出“Data”窗口:(2)利用X data和Y data的下 ...
- 使用copy来拷贝对象
拷贝对象 您通过将 copy 消息发送给对象,以制作对象的副本. NSArray *myArray = [yourArray copy]; 要拷贝,接收对象的类必须遵守 NSCopying 协议.如果 ...
- PHP oracle分页
oracle分页 function getall($query, $start=0, $rows=-1) { $this->dbh = oci_connect('aaa','mmm'," ...
- 第一次div1做出3道题
第一次div1做出3道题! 再接再厉! 哈利路亚!
- Sonar + Jacoco,强悍的UT, IT 双覆盖率统计(转)
以前做统计代码测试覆盖,一般用Cobertura.以前统计测试覆盖率,一般只算Unit Test,或者闭上眼睛把Unit Test和Integration Test一起算. 但是,我们已经过了迷信UT ...