#include<bits/stdc++.h>
#define s(x) scanf("%d",&x);
#define p(x) printf("%d",x);
#define ps(x) printf(x);
#define f(x,y,z) for(int x=y;x<=z;x++)
#define r return 0;
using namespace std;
int n,m,dis[5010],a[5010][5010],x,y,z,minn,k,b[5010],ans;
int main()
{
cin>>n>>m;
memset(a,0x3f,sizeof(a));
f(i,1,m)
{
s(x)s(y)s(z)
a[x][y]=z;
}
memset(dis,0x3f,sizeof(dis));
dis[1]=0;
f(i,1,n)
{
minn=0x3f3f3f3f;k=0;
f(j,1,n)
{
if(b[j]==0&&dis[j]<minn)
{
minn=dis[j];
k=j;
}
}
if(k==0)
{
ps("orz");
r
}
b[k]=1;
ans+=dis[k];
f(j,1,n)
{
if(b[j]==0&&a[k][j]<dis[j]) dis[j]=a[k][j];
}
}
p(ans);
r
}
本人码风较差,请大家多多谅解