, greater > f; , greater > f;// luogu-judger-enable-o2
#include
#define INF 0x7fffffff
#define mp make_pair
#define ll long long
#define P pair
using namespace std;
const int maxn = 1000000 + 10;
int head1[maxn], cnt1, cnt2, n, m, head2[maxn];
ll dis[maxn], ans;
bool vis[maxn];
struct edge{ int fr, to, w, nxt; bool mod; } e1[maxn], e2[maxn];
void add1(int u, int v, int w) { e1[++cnt1].fr = u, e1[cnt1].to = v, e1[cnt1].w = w, e1[cnt1].nxt = head1[u], head1[u] = cnt1; }
void add2(int u, int v, int w) { e2[++cnt2].fr = u, e2[cnt2].to = v, e2[cnt2].w = w, e2[cnt2].nxt = head2[u], head2[u] = cnt2; }
void dij1() {
priority_queue<P, vector
for (int i = 1; i dis[st] + e1[i].w) {
dis[e1[i].to] = dis[st] + e1[i].w, f.push(mp(dis[e1[i].to], e1[i].to));
}
}
}
for (int i = 2; i <= n; ++i) ans += dis[i];
}
void dij2() {
priority_queue<P, vector
for (int i = 1; i dis[st] + e2[i].w) {
dis[e2[i].to] = dis[st] + e2[i].w, f.push(mp(dis[e2[i].to], e2[i].to));
}
}
}
for (int i = 2; i <= m; ++i) ans += dis[i];
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++i) { int u, v, w;
scanf("%d %d %d", &u, &v, &w);
add1(u, v, w), add2(v, u, w);
}
dij1(), dij2();
printf("%lld", ans);
return 0;
}