kruscal模板题,思路参考刘汝佳算法竞赛入门经典(第2版)例11-2
#include<iostream>
#include<cstdio>
#include<set>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn = 100 + 7;
int fa[maxn];
int m, n;
int find(int x) {//并查集
return fa[x] = fa[x] == x ? x : find(fa[x]);
}
void Union(int x, int y) {
int fx = find(x);
int fy = find(y);
if (fx != fy)
fa[fx] = fy;
}
struct p {
int u, v, w;//起点,中点,权值
};
bool cmp(p& a, p& b) {
return a.w < b.w;
}
void init() {//初始化并查集
for (int i = 0; i <= m; i++) {
fa[i] = i;
}
}
vector<p>vec;
int kruscal(int L) {