MST  Minimum Spanning Tree
Find the minimum spanning tree of the graph.
Input
On the first line there will be two integers N  the number of nodes and M  the number of edges. (1 <= N <= 10000), (1 <= M <= 100000)
M lines follow with three integers i j k on each line representing an edge between node i and j with weight k. The IDs of the nodes are between 1 and n inclusive. The weight of each edge will be <= 1000000.
Output
Single number representing the total weight of the minimum spanning tree on this graph. There will be only one possible MST.
Example
Input: 4 5 1 2 10 2 3 15 1 3 5 4 2 2 4 3 40 Output: 17
Added by:  Nikola P Borisov 
Date:  20081020 
Time limit:  1s2s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel Pentium G860 3GHz) 
Languages:  All except: ERL JS NODEJS PERL 6 SCM chicken VB.net 
hide comments
Bhargav Parsi:
20150212 10:00:19
i am getting a compilation error although my code runs fine in ideone!..plz help 

Sonu Sharma:
20150111 09:44:31
@paci :fair enough!!! 

Antony Skarlatos (Hepic):
20141109 10:51:39
Use long long for distance(or weight),to take 100%.


Umair Khan:
20140926 20:51:21
long long gives 100. 

ayush:
20140614 10:29:43
Thank You Aman 

elgun:
20140122 18:36:32
AC


dslearner:
20140115 17:51:31
isnt this problem same as http://www.spoj.com/problems/CSTREET/


William Macfarlane:
20130902 05:29:48
Aman Gupta,


Avneet:
20130612 10:18:48
my solution got accepted , but result is 0 , wht it means ? 

Lại Mạnh Tuấn:
20130110 10:55:14
@ Aman Gupta: Thanks for the suggestion 