#include #define INF 10e9 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; typedef struct edge { int to; int cost; } edge; int main() { long long int n, m; cin >> n >> m; vector graph[n]; long long int u, v, c; long long int i, j; for (i = 0; i < m; i++) { cin >> u >> v >> c; edge e; e.to = v - 1; e.cost = c; graph[u - 1].push_back(e); e.to = u - 1; graph[v - 1].push_back(e); } long long int d[2][n]; for (i = 0; i < n; i++) { if (i == 0) { d[0][i] = 0; d[1][i] = 0; } else { d[0][i] = INF; d[1][i] = INF; } } priority_queue, long long int>, vector, long long int>>, greater, long long int>>> q; q.push(make_pair(make_pair(0, 0), 0)); while (!q.empty()) { pair, long long int> p = q.top(); q.pop(); long long int v = p.first.first; if ((p.second == 0) && (d[0][v] >= p.first.second)) { for (i = 0; i < graph[v].size(); i++) { edge e = graph[v][i]; if (p.second == 0) { if (d[0][e.to] > d[0][v] + e.cost) { d[0][e.to] = d[0][v] + e.cost; q.push(make_pair(make_pair(e.to, d[0][e.to]), 0)); } if (d[1][e.to] > d[0][v]) { d[1][e.to] = d[0][v]; q.push(make_pair(make_pair(e.to, d[1][e.to]), 1)); } } } } else if ((p.second == 1) && (d[1][v] >= p.first.second)) { for (i = 0; i < graph[v].size(); i++) { edge e = graph[v][i]; if (d[1][e.to] > d[1][v] + e.cost) { d[1][e.to] = d[1][v] + e.cost; q.push(make_pair(make_pair(e.to, d[1][e.to]), 1)); } } } } for (i = 0; i < n; i++) { cout << (d[0][i] + d[1][i]) << endl; } }