#pragma GCC optimize("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; using namespace std; typedef long long int ll; typedef unsigned long long int ull; struct edge { ll to; ll cost; }; typedef pair < ll, ll > P; void dijkstra(int s, vector>& g, vector &d) { priority_queue > q; d = vector(g.size(), INF_LL); d[s] = 0; q.push({ 0, s }); while (!q.empty()) { P p = q.top(); q.pop(); ll v = p.second; if (d[v] < p.first)continue; for (int i = 0; i < g[v].size(); i++) { edge e = g[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; q.push({ d[e.to], e.to }); } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector> g1(N),g2(N*2); for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; g1[a].push_back({ b,c }); g1[b].push_back({ a,c }); g2[a].push_back({ b,c }); g2[b].push_back({ a,c }); g2[a].push_back({ b + N,0 }); g2[b].push_back({ a + N,0 }); g2[a + N].push_back({ b + N,c }); g2[b + N].push_back({ a + N,c }); } vector d1(N), d2(N * 2); dijkstra(0, g1, d1); dijkstra(0, g2, d2); for (int i = 0; i < N; i++) { cout << min(d1[i] + d2[i + N], d1[i] * 2) << endl; } }