#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 105
using namespace std;
Int father[maxn], son[maxn];
Struct eage
{
Int a;
Int b;
Int eg;
}e[maxn];
Bool cmp(const eage & a, const eage & b)
{
Return a.eg < b.eg;
}
Int research(int a)
{
Return a == father[a] ? a : research(father[a]);
}
bool join(int a, int b)
{
Int root1, root2;
Root1 = research(a);
Root2 = research(a);
If(root1 == root2)
Return false;
Else if(son[root1] >= son[root2])
{
Father[root2] = root1;
Son[root1] += son[root2];
}
Else
{
Father[root1] = root2;
Son[root2] += son[root1];
}
Return true;
}
Int main()
{
Int i, n, en, nn = 0, ans = 0, flag = 0;
Scanf(“%d%d”,&n, &en);
For(i = 0;i < en;i++)
{
Scanf(“%d%d%d”,&e[i].a, &e[i].b, &e[i].eg);
}
Sort(e, e + en - 1, cmp);
For(i = 0;i < n;i++)
{
Father[i] = i;
Son[i] = 1;
}
For(i = 0;i < en;i++)
{
If(join(e[i].a, e[i].b))
{
Nn++;
Ans += e[i].eg;
}
If(nn == (n - 1)
{
Flag = 1;
Break;
}
}
If(flag == 1)
Printf(“%d\n”, ans);
Else
Printf(“impossible!\n”);
}