并查集
文章平均质量分 57
iYUNDI
iYUNDI
展开
-
[hoj 1225]Supermarket代码阅读记录
代码来源:http://hi.baidu.com/chingfantsou/item/fb84b21438ac14e55f53b194#include #include using namespace std;int n;int p[10001],d[10001];int md;int ans;int h[10001];struct pro{ int p,原创 2013-07-29 15:15:53 · 786 阅读 · 0 评论 -
[poj 1611]The Suspects[并查集模板][递归与非递归实现]
/*Model One*///364K 47MS[poj上递归略快一些~]#include#includeusing namespace std;const int MAXSIZE = 30005;int parent[MAXSIZE];//根节点储存-num(该树节点数),子节点储存父节点int Find(int x){//递归的路径压缩 if(parent[x]>=0)原创 2013-07-29 11:15:18 · 1095 阅读 · 0 评论 -
[poj 2524]Ubiquitous Religions[并查集]
题意:有n个学生,m对样本.每对样本x,y表示编号为x,y(从1开始)的学生有相同的宗教信仰.问n个学生共涉及多少个不同的宗教.裸并查集...#include #include using namespace std;const int MAXN = 50005;int set[MAXN];//father or -numvoid Init(void){原创 2013-07-29 13:04:04 · 721 阅读 · 0 评论 -
[poj 1182]食物链[并查集][图解+注释]
代码来源:http://blog.csdn.net/c0de4fun/article/details/7318642题意:动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法原创 2013-07-29 21:33:15 · 1418 阅读 · 0 评论