#include using namespace std; using ll = long long; const ll INF = 2e18; int main(){ int N,M; cin >> N >> M; vector edge(N,vector>(0)); vector C(M,0); for(int i = 0; i < M; i++){ int a,b; ll c; cin >> a >> b >> c; a--,b--; c = 1000000001ll - c; edge[a].push_back({b,c,i}); edge[b].push_back({a,c,i}); C[i] = c; } priority_queue,vector>,greater>> que; que.push({0,0,-1}); vector dist(N,INF); ll ans = 0; while(que.size()){ int now,edgenumber; ll time; tie(time,now,edgenumber) = que.top(); que.pop(); if(time >= dist[now])continue; dist[now] = time; if(edgenumber != -1)ans += 1000000001 - C[edgenumber]; for(auto j : edge[now]){ int to,TEN; ll totime; tie(to,totime,TEN) = j; if(time + totime < dist[to])que.push({time + totime,to,TEN}); } } cout << ans * 2 << endl; return 0; }