Pure_Echo @ 2024-08-06 16:52:37
#include<bits/stdc++.h>
using namespace std;
int n,m;
int fu[5010];
struct op{
int u,v,w;
}e[20010];
bool cmp(op x,op y){
return x.w<y.w;
}
int fin(int x){
if (x!=fu[x]) return fu[x]=fin(fu[x]);
return x;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++) cin>>e[i].u>>e[i].v>>e[i].w;
sort(e+1,e+m+1,cmp);
for(int i=1;i<=n;i++) fu[i]=i;
int cnt=0,ans=0;
for(int i=1;i<=m;i++){
int u=fin(e[i].u);
int v=fin(e[i].v);
if(u==v) continue;
fu[v]=u;
cnt++;
ans+=e[i].w;
}
if(cnt!=n-1) printf("orz");
else cout<<ans;
return 0;
}
by Super_Cube @ 2024-08-06 17:06:33
@Doyouknow8 e[200010]
by OrinLoong @ 2024-08-06 17:08:40
@Doyouknow8 e开小了,打少一个0
by Pure_Echo @ 2024-08-06 18:37:46
谢谢!