附上错误代码
//kruskal
//最小生成树
//small
//sort
#include<bits/stdc++.h>
using namespace std;
int fa[5005];
struct node{
int u, v, w;
}a[200005];
bool cmp(node x, node y){
return x.w < y.w;
}
int find(int x){
return fa[x] == x ? x : fa[x] = find(fa[x]);
}
void merge(int x, int y){
fa[find(x)] = find(y);
}
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
signed main(){
int n = read(), m = read();
for(int i = 0; i < m; i++){
cin >> a[i].u >> a[i].v >> a[i].w;
}
sort(a, a + m, cmp);
for(int i = 0; i <n; i++){
fa[i] = i;
}
int tot = 0;
for(int i = 0; i < m; i++){
if(find(a[i].u) != find(a[i].v)){
merge(a[i].u, a[i].v);
tot += a[i].w;
}
}
cout << tot;
return 0;
}
我知道要输出orz,but,我不知道怎么输出