(并查集)A Bug's Life -- POJ -- 2492
链接:
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的更多相关文章
- A Bug's Life POJ - 2492 (带权并查集)
A Bug's Life POJ - 2492 Background Professor Hopper is researching the sexual behavior of a rare spe ...
- A Bug’s Life POJ - 2492(种类并查集)
题目链接 每次给出两个昆虫的关系(异性关系),然后发现这些条件中是否有悖论 就比如说第一组数据 1 2 2 3 1 3 1和2是异性,2和3是异性,然后说1和3是异性就显然不对了. 我们同样可以思考一 ...
- A Bug's Life POJ - 2492 (种类或带权并查集)
这个题目的写法有很多,用二分图染色也可以写,思路很好想,这里我们用关于并查集的两种写法来做. 题目大意:输入x,y表示x和y交配,然后判断是否有同性恋. 1 带权并查集: 我们可以用边的权值来表示一种 ...
- 并查集+关系的传递(poj 1182)
题目:食物链 题意:给定一些关系.判断关系的正确性,后给出的关系服从之前的关系: 思路:难点不在并查集,在于关系的判断,尤其是子节点与根节点的关系的判断: 这个关系看似没给出,但是给出子节点与父节点的 ...
- A Bug's Life POJ 2492
D - A Bug's Life 二分图 并查集 BackgroundProfessor Hopper is researching the sexual behavior of a rare spe ...
- POJ 2492 (简单并查集) A Bug's Life
题意:有编号为1~n的虫子,开始假设这种昆虫是异性恋.然后已知xi 和 yi进行交配,根据已知情况分析能否推理出其中是否有同性恋 这道题和 POJ 1182 食物链 十分相似,不过在更新与父节点关系的 ...
- POJ 2492 并查集 A Bug's Life
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- (并查集 建立关系)Parity game -- POJ -1733
链接: http://poj.org/problem?id=1733 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#probl ...
随机推荐
- Null value was assigned to a property of primitive type setter of"原因及解决方法
在action请求数据的过程中报出"Null value was assigned to a property of primitive type setter of"错误,搜索之 ...
- webpack前端模块加载工具
最近在看许多React的资料,发现了大部分的项目都是用webpack行模块化管理的工具.这次也是借着写了一个React-Todos的小应用,对webPack最基本实用的功能体验了一番,顺带做个小记录. ...
- Tensorflow从文件读取数据
http://blog.csdn.net/zengxyuyu/article/details/53289906
- R语言做条形图时候,离散变量和连续型变量的区别
1)条形图 条形图或许是最常用图形,常用来展示分类(different categories on the x-axis)和数值(numeric values on the y-axis)之间的关系. ...
- sqldatareader无法得到output参数的解决
只需要在所有的sqldatareader结束后,加上一句就可以得到输出参数了. sdr.Close(); Object ObjCount = cmd.Parameters["@Count_P ...
- php拓展安装
Yaf安装配置:http://www.laruence.com/manual/yaf.install.html#yaf.installation.linux 下载Yaf的最新版本, 解压缩以后, 进入 ...
- DP解LCS问题模板及其优化
LCS--Longest Common Subsequence,即最长公共子序列,一般使用DP来解. 常规方法: dp[i][j]表示字符串s1前i个字符组成的字符串与s2前j个字符组成的字符串的LC ...
- phpStudy7——MySql数据库的增删查改
1. 添加数据: //添加数据 $strsql = "insert into user_info(userId,userName,phoneNumber,userScore,dataTime ...
- [udemy]WebDevelopment_How the Internet Works
Browsing the web Enter google.com, who is this google.com This question gets asked all the way down ...
- 如何进入/home/user/.wine
命令行输入 :cd /home/user/.wine/drive_c/windows/fonts /home是linux的用户目录,/user是用户名/.wine是隐藏目录,凡是以.开头的都是隐藏目录 ...