@[Dlive·Lx](/space/show?uid=94229) 边开小了
by Dog_Two @ 2018-11-08 17:56:22
呃
by ueettttuj @ 2018-11-08 17:57:18
```cpp
#include <bits/stdc++.h>
using namespace std;
long long n,m;
struct EDGE{
long long x,y,z;
};
EDGE edge[200100];
long long cmp ( EDGE a , EDGE b ){
return a.z<b.z;
}
long long a[70100];
long long root(long long kk){
if(a[kk]!=kk) a[kk]=root(a[kk]);
return a[kk];
}
int main(){
scanf("%lld %lld",&n,&m);
for(long long i=1;i<=m;i++){
scanf("%lld %lld %lld",&edge[i].x , &edge[i].y , &edge[i].z);
}
sort(edge+1,edge+m+1,cmp);
for(long long i=1;i<=n;i++)
a[i]=i;
long long ans=0;
for(long long j=1;j<=m;j++){
long long k1,k2;
k1=root(edge[j].x);
k2=root(edge[j].y);
if(k1!=k2){
a[k1]=k2;
ans+=edge[j].z;
}
}
printf("%lld\n",ans);
return 0;
}
```
by ueettttuj @ 2018-11-08 17:57:54
楼上正解
by Zenurik @ 2018-11-08 17:57:59
我的代码QAQ
by ueettttuj @ 2018-11-08 17:58:05
额,我试一下
by Dlive·Lx @ 2018-11-08 18:37:15
@[Dog_Two](/space/show?uid=38283) 我试一下
by Dlive·Lx @ 2018-11-08 18:41:08
果然是,在这里先谢谢各位大佬的指教。
by Dlive·Lx @ 2018-11-08 18:44:22