
数据结构-并查集
文章平均质量分 71
___Evan
这个作者很懒,什么都没留下…
展开
-
并查集模板
#include "stdio.h"const int maxn = 1005;int n,m;int p[maxn],rank[maxn]; int find( int x ){ if( p[x] == x ) return p[x]; else { return p[x] = find( p[x] );原创 2013-11-02 22:42:15 · 485 阅读 · 0 评论 -
hdu-1811 Rank of Tetris 并查集+拓扑
题目链接原创 2014-08-13 15:01:49 · 384 阅读 · 0 评论 -
poj-1733 Parity game 并查集
题目链接原创 2014-07-27 14:28:37 · 397 阅读 · 0 评论 -
Poj-2912 Rochambeau 枚举+并查集
#include "stdio.h"#include "map"#include "queue"#include "iostream"#include "functional"#include "math.h"#include "algorithm"using namespace std;const int maxn = 2005;const int mod = 10000000原创 2014-07-27 13:59:20 · 448 阅读 · 0 评论 -
poj-1417 True Liars 并查集+DP
#include "stdio.h"#include "map"#include "queue"#include "iostream"#include "functional"#include "math.h"#include "algorithm"using namespace std;const int maxn = 1005;const int mod = 10000000原创 2014-07-27 14:07:40 · 509 阅读 · 0 评论 -
poj-2524 Ubiquitous Religions 并查集
题目#include #include #include #include #include using namespace std;typedef long long LL;const int maxn = 50005;const int Mod = 1000000007;const int inf = 1<<30;int n,m;int p[maxn];in原创 2014-07-27 14:54:59 · 421 阅读 · 0 评论 -
POJ-1182 食物链 经典并查集
题目链接原创 2014-04-13 12:40:49 · 439 阅读 · 0 评论 -
POJ-2492 A Bug's Life 并查集
题目链接原创 2014-04-13 16:47:39 · 401 阅读 · 0 评论 -
POJ-1703 Find them, Catch them 经典并查集
#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 100005;const int inf = 1<<29;int n,m;int p[maxn],g[maxn]; //g 0表示相同 1表示不同in原创 2014-04-13 16:11:17 · 434 阅读 · 0 评论 -
HDU-1272 小希的迷宫 并查集
题目链接#include "stdio.h"const int maxn = 100050;int p[maxn],rank[maxn];bool vis[maxn];int n,flag;int find( int x ){ return p[x] == x ? x:p[x] = find(p[x]);}void merge( int a,int原创 2014-01-19 12:01:48 · 438 阅读 · 0 评论 -
HDU-3635 Dragon Balls 并查集路径压缩
http://acm.hdu.edu.cn/showproblem.php?pid=3635题目大意:初始时,有n个龙珠,编号从1到n,分别对应的放在编号从1到n的城市中。现在又2种操作:T A B,表示把A球所在城市全部的龙珠全部转移到B城市。(第一次时,因为A球所在的城市只有一个球,所以只移动1个,如果有多个,则全部移动)。Q A,表示查询A。要求得原创 2014-02-05 15:27:44 · 545 阅读 · 0 评论 -
POJ-3522 Slim Span 最小生成树最小边权差
题目大意:n个点m条边 用n-1条边连接n个点并边权差最小思路:枚举最小边 + Kruskal#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 105;const int inf = 1<<30;int n,m原创 2014-01-19 22:35:49 · 521 阅读 · 0 评论 -
HDU-3038 How Many Answers Are Wrong
题目链接#include #include #include using namespace std;#define maxn 200020int n,m;int p[maxn],weight[maxn]; //并查集祖先结点 并查集权值int find(int x){ if( p[x] == x ) return x; int t =原创 2014-01-19 12:08:36 · 372 阅读 · 0 评论 -
HDU-3461 Code Lock 并查集 + 二分求幂
题目链接题意是说有N个字母组成的密码锁, 如【wersdfj】, 每一位上的字母可以转动, w可转动变成x, z变成a。但是题目规定, 只能同时转动某个区间上的所有字母, 如【1,3】, 那么第1到第3个的所有字母要同时转动,那么【 wersdfj 】经过一次操作就变成 【 xfssdfj 】. 一共有M 个区间是可以操作的。 题目还规定:If a lock c原创 2014-01-24 14:42:12 · 592 阅读 · 0 评论 -
HDU-3172 Virtual Friends 并查集+map
题目链接#include#include#include#include#include#include#include#include#includeusing namespace std;const int maxn = 100050;const int inf = 1<<30;int n,m;int p[maxn],mark[maxn];mapmaps;in原创 2014-01-24 13:30:33 · 470 阅读 · 0 评论 -
HDU-3038 How Many Answers Are Wrong 带权并查集
#include #include #include using namespace std;#define maxn 200020int n,m;int p[maxn],weight[maxn]; //并查集祖先结点 并查集权值int find(int x){ if( p[x] == x ) return x; int t = p[x]; p[原创 2013-11-02 22:44:27 · 413 阅读 · 0 评论 -
HDU-2473 Junk-Mail Filter 并查集的删除
/*解决方法: 为每一个结点加一个虚根,这样每个结点都是叶子结点.插入结点时,把它们都并到虚根的集合中.删除结点时,只要把它的父结点置为一个无用的虚根*/#include#include#include#includeusing namespace std;const int maxn = 1000005;const int inf = 1<<30;int n,m;int原创 2013-11-02 22:43:53 · 534 阅读 · 0 评论 -
HDU-1116 Play on Words 并查集
/*http://acm.hdu.edu.cn/showproblem.php?pid=1116题意:有n个字符串,问能不能将n个字符串连接起来,使得每一个字符串的首字母等于前一个字符串的尾字母,每个字符串必须连进去一次。题解:欧拉回路,把每个字符串看成一个一条边,一条从头到尾的有向边,首尾的两个字符看成图中的两个点,建立一个邻接矩阵。然后求每个点的入度和出度,如果有一点入度为0,出度原创 2013-11-02 22:42:56 · 578 阅读 · 0 评论 -
hdu-3926 Hand in Hand 并查集
题目链接#include #include #include #include #include #include #include using namespace std;typedef __int64 LL;const int maxn = 10005;const int Mod = 1000000007;int n1,m1,n2,m2;int p1[max原创 2014-08-16 23:32:08 · 563 阅读 · 0 评论