#include using namespace std; #define int long long typedef pair P; int INF = 3e18+7; int mod = 1e9+7; int dx[] = {1, 0,-1, 0, 1, 1,-1,-1}; int dy[] = {0, 1, 0,-1, 1,-1, 1,-1}; signed main() { int N,M; cin >> N >> M; vector>road(N); for(int i = 0; i < M; i++) { int s,t,d; cin >> s >> t >> d; s--;t--; if(!road[s].count(t)) { road[s][t] = d; } road[s][t] = min(road[s][t],d); } for(int i = 0; i < N; i++) { vectordist(N,INF); dist[i] = 0; priority_queue,greater

>que; que.push({0,i}); while (!que.empty()) { P x = que.top(); que.pop(); if(x.first > dist[x.second]) { continue; } for(P X:road[x.second]) { if(dist[X.first] > x.first+X.second) { dist[X.first] = x.first+X.second; que.push({dist[X.first],X.first}); } } } int ans = 0; for(int j = 0; j < N; j++) { if(dist[j] == INF) { continue; } ans += dist[j]; } cout << ans << endl; } }