#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
int x,y;
int t;
friend bool operator < (node a, node b)
{
return a.t > b.t;
}
};
int f[5010];
int find(int x)
{
return f[x] == x ? x:f[x]=find(f[x]);
}
priority_queue<node>q;
node now;
int main()
{
// freopen("D:\\P3366_2.in","r",stdin);
// freopen("C:\\Users\\76004\\Desktop\\新建文本文档.txt","w",stdout);
int n,m;
cin>>n>>m;
for(int i = 1; i <= n; i++) f[i] = i;
while(m--)
{
int x,y,z;
cin>>x>>y>>z;
now.x = x;
now.y = y;
now.t = z;
q.push(now);
}
int ans = 0;
int cnt = n;
while(cnt > 1)
{
if(!q.empty())
now = q.top();
else
break;
if(find(now.x) != find(now.y))
{
f[find(now.x)] = find(now.y);
ans += now.t;
cnt--;
}
q.pop();
}
for(int i = 1; i <= n; i++)
find(i);
for(int i = 2; i <= n; i++)
if(f[i] != f[i-1])
{
printf("orz\n");
return 0;
}
printf("%d\n",ans);
}
07-22
07-22
07-22