题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1829 题意:就是给你m条关系a与b有性关系,问这些关系中是否有同性恋 这是一道简单的种类并查集,而且也比较简单只要比较给出的两个点是否有相同祖宗如果有那么他们距离祖宗结点的距离是否为偶数 如果是偶数那么他(她)们必然是同性恋. #include <iostream> #include <cstring> #include <cstdio> using namespace s…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1829 A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 19429    Accepted Submission(s): 6206 Problem Description Background Professor H…
http://acm.hdu.edu.cn/showproblem.php?pid=1829   A Bug's Life Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1829 Description Background Professor Hopper is researching the sexual behavior of a…
A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 45757   Accepted: 14757 题目链接:http://poj.org/problem?id=2492 Description: Background : Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes…
题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父亲是否相同,若父亲相同,用向量算的父亲之间的关系和之前的关心有矛盾没,有矛盾就是有错. 2.如果不在一个集合,就合并他们的父亲,用向量根据根节点的关心求出父亲的关心,然后合并. 这是并查集的重要的操作路径压缩,路径压缩的时候关心就要更新比如 1- 2 是异性 2 - 3 是异性 那么1,2,3在同一…
wyh2000 and pupil Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 755    Accepted Submission(s): 251 Problem Description Young theoretical computer scientist wyh2000 is teaching his pupils. Wy…
A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9204    Accepted Submission(s): 2961 Problem Description Background Professor Hopper is researching the sexual behavior of a rare sp…
题目链接 食物链类似的题,主要是在于转化,a-b的和为s,转换为b比a-1大s.然后并查集存 此节点到根的差. 假如x的根为a,y的根为b: b - y = rank[y] a - x = rank[x] y - x = s 可以推出b - a = rank[y] - rank[x] + s; 并查集 延迟更新什么的,都忘了啊. 还有这题,如果是x--的话,记得更新0的根. #include <cstring> #include <cstdio> #include <stri…
把性别相同的虫子放在同一个集合,然后每读入一对虫子号,判断它们在不在同一集合,在则同性别,不在则继续 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; int fa[maxn]; int Rank[maxn]; int group[maxn]; void init(int x){ fa[x] = x; Rank[x] = ; group[x] = ; } in…
题目的大意可以理解为:A爱B,B爱C ……给出一系列爱恋的关系,推断有没有同性恋. 思路是把相同性别的归为一个集合(等价类),异性的异性为同性. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int f[N], r[N], flag; void init() { ;i<N;i++) { f[i]=i; r[…