题目链接:https://www.luogu.org/problem/P3366 最小生成树模板题. Kruskal算法 算法思想:给边按边权从小到大排序,然后遍历每一条边,如果边上的两个点不在同一个集合,则选择这条边,并将两个点所在集合合并.直到选择了 \(n-1\) 条边. 实现代码如下: #include <bits/stdc++.h> using namespace std; const int maxn = 200200; int n, m, f[5050], cnt, u[maxn
题意 题目链接 Sol 自己yy着写了一下Boruvka算法. 算法思想很简单,就是每次贪心的用两个联通块之间最小的边去合并. 复杂度\(O(n \log n)\),然鹅没有Kruskal跑的快,但是好像在一类生成树问题上很有用 #include<bits/stdc++.h> #define Pair pair<int, int> #define fi first #define se second #define pb push_back #define getchar() (p
传送门啦 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define re register using namespace std; const int maxn = 5005; const int maxm = 200005; inline int read(){ char ch = getchar(); int f = 1 , x = 0;
To 洛谷.1432 倒水问题 题目背景 In the movie "Die Hard 3", Bruce Willis and Samuel L. Jackson were confronted with the following puzzle. They were given a 3-gallon jug and a 5-gallon jug and were asked to fill the 5-gallon jug with exactly 4 gallons. This