kruskal方法(前置权值排序+并查集)
class UnionFind{
private:
int root_num;//联通分量个数
vector<int> father;//存储树
vector<int> subnode;//记录包含当前节点及子节点的个数,用于树的平衡
public:
UnionFind(int n){
root_num=n;
father.resize(n+1);
subnode.resize(n+1);
for(int i=1;i<n+1;i++){
father[i]=i;
subnode[i]=1;
}
}
int find(int node){
while(father[node]!=node){
father[node]=father[father[node]];//路径压缩
node=father[node];
}
// while(father[node]!=root){
// int pre_father=father[node];
// father[node]=root;
// node=pre_father;
// }
return node;
}
void connect(int x,int y){
int r