module.exports=function(t){var r={};function n(i){if(r[i])return r[i].exports;var e=r[i]={i:i,l:!1,exports:{}};return t[i].call(e.exports,e,e.exports,n),e.l=!0,e.exports}return n.m=t,n.c=r,n.d=function(t,r,i){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var e in t)n.d(i,e,function(r){return t[r]}.bind(null,e));return i},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="",n(n.s=0)}([function(t,r,n){"use strict";var i=n(1);n(2)(i.readFileSync("/dev/stdin","utf8"))},function(t,r){t.exports=require("fs")},function(t,r,n){"use strict";var i=n(3),e=n(5);t.exports=function(t){var r=new i(t);e(r)}},function(t,r,n){"use strict";var i=n(4);t.exports=class{constructor(t){var r=t.trim().split(/\s+/g);this.inp=new i(r)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,r,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,r,n){"use strict";var i=n(6);t.exports=function(t){for(var r=t.in(),n=t.in(),e=new Array(n),s=0;s<n;s++){var o=t.in(),u=t.in(),a=t.in();e.push({s:o,t:u,c:a}),e.push({s:u,t:o,c:a})}for(var c=i(r,e),f=0,h=c.length,p=0;p<h;p++)f+=c[p].c;console.log(f)}},function(t,r,n){"use strict";var i=n(7);t.exports=function(t,r){var n=new i(t),e=[],s=r.concat();s.sort(function(t,r){return t.c-r.c});for(var o=0;e.length<t-1;){var u=s[o++];n.isSameGroup(u.s,u.t)||(e.push(u),n.unite(u.s,u.t))}return e}},function(t,r,n){"use strict";t.exports=class{constructor(t){this.N=t,this.par=new Array(this.N),this.rank=new Array(this.N);for(var r=0;r<this.N;r++)this.par[r]=r,this.rank[r]=0}find(t){return this.par[t]==t?t:this.par[t]=this.find(this.par[t])}unite(t,r){var n=this.find(t),i=this.find(r);n!=i&&(this.rank[n]<this.rank[i]?this.par[n]=i:(this.par[i]=n,this.rank[n]==this.rank[i]&&this.rank[n]++))}isSameGroup(t,r){return this.find(t)==this.find(r)}}}]);
