![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
----------并查集
mfcheer
他不停地跑啊跑 就为了追上那个曾经被寄予厚望的自己
展开
-
hdu-2545
并查集的扩展应用,求节点到根的距离原创 2014-10-28 09:08:04 · 514 阅读 · 0 评论 -
图论——并查集
/* 并查集模板 by:mfcheer*/#include #include #include #include #include #include #include #include #include using namespace std;#define N 100010int n, m;int fa[N];int原创 2015-01-24 18:30:44 · 791 阅读 · 0 评论 -
hdu-1232 畅通工程
http://acm.hdu.edu.cn/showproblem.php?pid=1232并查集#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include #include #原创 2015-01-06 20:32:36 · 588 阅读 · 0 评论 -
hdu-1325 & poj-1308 Is It A Tree?
http://acm.hdu.edu.cn/showproblem.php?pid=1325题意:判断一个图是不是说树 只有树的根入度为 0 ,其余结点入度均为 1;Is It A Tree?Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total原创 2015-01-24 16:47:37 · 871 阅读 · 0 评论 -
hdu-3038 带权并查集
http://acm.hdu.edu.cn/showproblem.php?pid=3038题意:Ai,Bi,Si 表示 Ai Bi 之间数的和是Si问与前面命题冲突的命题有几个。val [ i ] 表示 i 与 fa[ i ] 相差多大 。How Many Answers Are WrongProblem Descriptio原创 2015-01-24 20:53:22 · 552 阅读 · 0 评论 -
变形金刚 【并查集】
变形金刚 Description 有一天Stubird买了一台变形金刚,店员说,这台变形金刚和其他那种骗小孩子的不一样 他真的能变形。 这台变形金刚有n个部件,他们能互相连接,组成机器人,当然,也可以变形。 但是有一天,The tesseract 的能量突然消失了,部件散落一地,当然有些部件还连接着。 现在你只有把部件全部连接起来,他就能变回原样,例如,有4个部件,1,2是连接的,3,4也是连接原创 2015-03-17 00:18:45 · 1028 阅读 · 0 评论 -
hdu 5326 Work【并查集】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5326题意:n个点 ,给你m有向条边,表示起点是终点的父亲。问子孙节点个数是K的节点有几个?解法:并查集。代码:#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#inc原创 2015-07-28 20:24:57 · 601 阅读 · 0 评论 -
UVA 10608 Friends【并查集】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1549题意:给定n个人m种朋友关系,求最大朋友圈的人数。裸并查集代码:#include <stdio.h>#include <iostream>#include <string.h>#i原创 2015-08-12 16:25:09 · 599 阅读 · 0 评论 -
UVA 1329 Corporative Network【并查集】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4075题意: 有n个结点,开始都是单独的结点,现在有I操作和E操作,I u v表示吧u的父亲结点设为,距离为|u - v| % 1000,E操作询问u到根的距离代码:#include <std原创 2015-08-17 20:20:30 · 571 阅读 · 0 评论 -
poj-1182 种类并查集
转:用0 1 2 分别表示A B C的关系。0吃1,1吃2,2吃0.注意这个编号都是以根结点为参照的,不是绝对的。开一个val数组,一开始这个数组为0,所有的点都是独立的,不是相连的,没有关系。慢慢加入点之后,把有关系的合并在一起,并且编号的相对大小确定一个集合中的关系。#include #include #include原创 2015-01-19 16:14:23 · 701 阅读 · 0 评论 -
poj-1611 并查集
http://poj.org/problem?id=1611简单并查集,建设学号是0 的学生已经是感染者,问与他同集合的人有多少个。#include #include #include #include #include #include #include #include #include #include using namespace std;原创 2015-01-18 14:54:24 · 637 阅读 · 0 评论 -
hdu-1856
并查集最大秩原创 2014-10-18 13:51:45 · 474 阅读 · 0 评论 -
poj-1703
种类并查集: 分为1~N,N~2N两类;a,b第一次出现时是p[a]=a,p[b]=b;原创 2014-10-19 11:08:33 · 576 阅读 · 0 评论 -
poj-1611
找根节点是 0 相同的点的个数。原创 2014-10-18 11:07:06 · 412 阅读 · 0 评论 -
hdu-2120
并查集判环:原创 2014-10-18 11:45:02 · 552 阅读 · 0 评论 -
poj-2236
并查集:原创 2014-10-18 14:28:06 · 576 阅读 · 0 评论 -
hdu-1272
#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include #include #includeusing namespace std;int p[1000000];int ss原创 2014-10-18 11:52:10 · 434 阅读 · 0 评论 -
hdu-1213 how many tables
http://acm.hdu.edu.cn/showproblem.php?pid=1213并查集#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include #include #原创 2015-01-06 20:37:16 · 609 阅读 · 0 评论 -
hdu-1829 & poj-2492 并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1829#include #include #include #include #include #include #include #include #include #include using namespace std;int t, n, m;int fa[2200]原创 2015-01-19 11:00:36 · 768 阅读 · 0 评论 -
UVA 1160 X-Plosives【并查集】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3601题意: 每次给定一个两个元素a,b组成的化合物,如果车上有k个化合物,又包含了k个元素,就会形成爆炸物,所以每次装上去前要检查一下,输入一些化合物,求不能装的个数代码:#include原创 2015-08-17 19:55:25 · 695 阅读 · 0 评论