很好的一道题.. 首先把边权排序.然后枚举最小的边,再依次添加不小于该边的边,直到s和t联通.用并查集维护即可. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map>…
正着不好搞,考虑倒着搞.倒着搞就是一个并查集. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # include <set> # include…
利用并查集按秩合并,保存每个点合并的时间: 求时间时,就一直跳u=fa[u],并记录路径上时间的最大值,代表最后一次合并的时间 #include<cstdio> #include<iostream> #define R register int ; using namespace std; inline int g() { R ret=,fix=; register :fix; +(ch^); while(isdigit(ch=getchar())); return ret*fix…
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4668 不路径压缩,维护并查集的树的结构,查询链上最大值.按秩合并就可以暴爬. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ; int n,m,fa[N],w[N],siz[N],tot,ans; int rd…