# Minimum Spanning Tree (Prims Algorithm)

/***
Minimum Spanning Tree (Prims Algorithm)
***/

#include <vector>
#include <list>

#include <map>

#include <set>

#include <deque>

#include <stack>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <queue>

using namespace std;

#define SIZE 10000

struct pq

{

int cost,node;

bool operator<(const pq &b)const

{

return cost>b.cost;    // Min Priority Queue

}

};

{

priority_queue<pq>Q;

vector<int>color(nodes);

pq U,V;

int i,sum;

V.node=source;

sum=V.cost=0;

Q.push(V);

while(!Q.empty())

{

U=Q.top();

if(color[U.node]==0)

sum+=U.cost;
color[U.node]=1;

Q.pop();

{

{

Q.push(V);

}

}

}

return sum;

}

int main()

{

int nodes,edges,i,u,v,cost,source,val;

pq V;

vector<int>dist;

while(scanf("%d %d",&nodes,&edges)==2)

{

for(i=0;i<nodes;i++)

{

}

for(i=0;i<edges;i++)

{

scanf("%d %d %d",&u,&v,&cost);

V.cost=cost;

V.node=v;

V.node=u;
//For Bidirectional Edges

}

printf("%d\n",val);

}

return 0;

}

Input:
5 7
0 1 5
0 2 4
1 2 2
1 4 3
2 4 1
2 3 4
3 4 3

Output: 10