# 题目

{% fold 点击显/隐题目 %}

5 29 1 2 674 2 3 249 3 4 672 4 5 933 1 2 788 3 4 147 2 4 504 3 4 38 1 3 65 3 5 6 1 5 865 1 3 590 1 4 682 2 4 227 2 4 636 1 4 312 1 3 143 2 5 158 2 3 516 3 5 102 1 5 605 1 4 99 4 5 224 2 4 198 3 5 894 1 5 845 3 4 7 2 4 14 1 4 185
92
{% endfold %}

# 代码

{% fold 点击显/隐代码 %}```cpp 最小生成树二·Kruscal算法 https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
#include
#include
using namespace std;

const int maxn = 1e5 + 5;
const int maxm = 1e6 + 5;

int f[maxn];
struct Edge {
int u, v;
int w;
bool operator<(const Edge rhs) const { return w < rhs.w; }
} e[maxm];
int pos;

int ufs(int x) { return f[x] == x ? x : f[x] = ufs(f[x]); }
int Kruskal(int n, int m) {
int w = 0;
for (int i = 0; i <= n; i++)
f[i] = i;
sort(e, e + m);
for (int i = 0; i < m; i++) {
int x = ufs(e[i].u), y = ufs(e[i].v);
if (x != y) {
f[x] = y;
w += e[i].w;
}
}
return w;
}
void addEdge(int u, int v, int w) {
e[pos].u = u;
e[pos].v = v;
e[pos].w = w;
pos++;
}

int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
int u, v, w;
pos = 0;
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &u, &v, &w);
`{% endfold %}`