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都为异性,先说的是对的,如果后面给出关系与前面的 ...
随机推荐
- 图像显示与加载——opencv(转)
cvLoadImage() 函数:IplImage* cvLoadImage("图像名称",参数): 函数作用:加载图片: 函数返回值:为IplImage结构体: 参数说明:参数值 ...
- gsoap框架下的onvif程序流程分析
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) { do { unsigned int k = soap->max_keep_al ...
- python抓取性感尤物美女图
由于是只用标准库,装了python3运行本代码就能下载到多多的美女图... 写出代码前面部分的时候,我意识到自己的函数设计错了,强忍继续把代码写完. 测试发现速度一般,200K左右的下载速度,也没有很 ...
- 生成1~n的全排列
输入正整数n,输出n的全排列. 样例输入1: 3 样例输出1: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 分析: 按字典序从小到大的顺序输出所有的排列. (字典序:两个序 ...
- 《J2EE,J2SE,J2ME》
J2EE(Java EE)是做企业级应用的.比如,163邮箱,比如某公司的管理系统 J2SE(Java SE)就是Java语言的标准版本,类似于C++,主要做桌面软件,比如Eclipse,MyEcli ...
- nslayoutConstraint
1.vfl的正确编写格式 NSDictionary *dict1 = NSDictionaryOfVariableBindings(_boxV,_headerL,_imageV,_backBtn,_d ...
- 04-树5 Complete Binary Search Tree
这题也是第二次做,本想第一次做时参考的算法会和老师讲的一样,不想老师讲的算法用在这题感觉还不如思雪园友的算法(http://www.cnblogs.com/sixue/archive/2015/04. ...
- vc设置按钮文字颜色
设置按钮文字颜色使用 CMFCBUTTON即可 在OnInitDialog函数加入如下内容即可 ((CMFCButton*)GetDlgItem(IDC_MFCBUTTON1))->SetTex ...
- 创建一个Windows窗体
20140702加: WS_OVERLAPPEDWINDOW这个属性如果写成WS_OVERLAPPED,则窗口没有最大最小按钮以及左边的系统的菜单. vs2010下的代码提示快捷键:CTRL + J ...
- HTML中的鼠标光标属性
在网页中默认的鼠标指针只有两种,一种是最普通的箭头,另一种是当移动到链接上时出现的“小手”.但现在越来越多的网页都使用了CSS鼠标指针技术,当将鼠标移动到链接上时,可以看到多种不同的效果.CSS可以通 ...