![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
并查集
并查集
Dream-chasing ant
鄙人水平不高,建立博客初心只是想留一份回忆给自己。
展开
-
Cube Stacking POJ - 1988
这道题,跟叠积木那道题完全一样,可惜我并查集好久没写了,生疏了。当时刚刚学会写题解,没有写注释,尴了个大尬。 v表示某堆栈上方有多少堆栈,d表示下方有多少 传送门 #include<cstdio> #include<iostream> using namespace std; const int maxn=2e5+10; int n,p; int z,x,y; int f[maxn],d[maxn],v[maxn]; inline void init(){ for(int i=.原创 2020-07-24 21:55:39 · 96 阅读 · 0 评论 -
Find them, Catch them POJ - 1703
传送门 题意:两个帮派,A,查询两人是否为同一个帮派,三种输出结果 D,两人不在同一个帮派。 思路:将两个帮派设置为两个集合,f[d]为一个集合的代表,f[d+n]为另一个集合的代表 #include<cstdio> #include<iostream> using namespace std; const int maxn=2e5+10; int n,m; int z,x,y; int f[maxn]; inline void init(){ for(int i=1;i<原创 2020-07-24 20:19:33 · 69 阅读 · 0 评论 -
并查集+经典例题
查并集原来以前看过,当时看的那篇文章编了一个江湖的关系,令我印象深刻,可惜我找不到了。 查并集相当于并集,把没有关系的集合分开 可以想象为朋友圈,我朋友的朋友,跟我是一个朋友圈的。 基础 模板题 #include<bits/stdc++.h> using namespace std; const int maxn=2e5+10; int n,m; int z,x,y; int f[ma...原创 2020-01-31 15:33:17 · 2985 阅读 · 7 评论