HDU 1811
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1811中文码题对于等号的情况,用并查集合并(因为编号不同一定可以分出先后)然后判断能否构成拓扑排序,以及拓扑排序是不是唯一的题不难,考验代码能力,能1A证明手感还不错#include #include #inclu...
阅读全文
hdu 3172
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3172题意:输出每对朋友的关系网大小并查集的时候维护一个数组记录根节点的大小即可,水题,这题坑在T组数据这个也要读到EOF,开始莫名其妙wa...#include #include #include #includ...
阅读全文
hdu 3635
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=36351-n个城市,对应放着编号1-n的龙珠。两种操作TAB把编号A的龙珠所在城市内的全部龙珠放到有编号B的龙珠的城市内QA查询编号A的龙珠的信息,输出三个数,A所在城市,A所在城市龙珠数目,A转移到该城市所用次数...
阅读全文
HDU 3047
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3047和hdu 3038以及poj那个食物链一样,都是带权并查集,此题做法和hdu 3038完全相同,具体操作看上篇博客这题原来写过,但是没过,直接改的原来代码#include #include #include ...
阅读全文
HDU 3038
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=3038题意:[1-n]的区间,有m个询问,每个询问表示[a,b]的和是s,问一共有多少组矛盾sum[i]表示i到根节点的和,求区间和用sum[b]-sum[a-1]为方便描述先把a--我是把b的父亲接在a的父亲上,...
阅读全文
POJ 1182
摘要:http://poj.org/problem?id=1182带权并查集第一题,三种类型的生物,分别加入三个集合,题解见注释#include #include #include using namespace std ;#define MAX_N 150005int par[MAX_N] ;//父亲 ...
阅读全文
并查集
摘要:#define MAX_N 50005int par[MAX_N] ;//父亲 int rank[MAX_N] ;//树的高度 void INIT(int n){ for(int i=0 ;i<n ;i++){ par[i]=i ; rank[i]=0 ; }...
阅读全文
HDU 1198
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1198裸并查集,主要工作在根据题目给出关系构图#include #include #include using namespace std ;int idx[2505] ;int m,n ;char M[55][5...
阅读全文
HDU 1213 How Many Tables
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1213和畅通工程是一个意思、、View Code #include #include #include int idx[2000];int n,m;int find(int x){ //找x所在并查集的根节点...
阅读全文
HDU 1232 畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1232第一次做并查集,有点小爽。。。View Code #include #include #include int idx[2000];int n,m;int find(int x){ //找x所在并查集的...
阅读全文