#include <iostream>
#include <vector>
#include <tuple>
#include <utility>
#include <queue>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
#define int long long

int32_t main()
{
#ifdef LOCAL_ABHAY
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m;
	cin >> n >> m;

	int t, i, j, k;
	vector<int> ret(n + 1, numeric_limits<int>::max());
	vector<bool> vis[4];
	for (i = 0; i < 4; i++)
		vis[i].assign(n + 1, false);
	vector<pair<int, int>> adj[n + 1]; // destination, weight
	for (i = 0; i < m; i++)
	{
		int u, v, w;
		cin >> u >> v >> w;
		// u--, v--;

		adj[u].push_back(make_pair(v, w));
		adj[v].push_back(make_pair(u, w));
	}

	// temp = tuple<int, int, int, int> // cost, node, mask, length
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> pq;
	pq.push(make_tuple(0, 1, 0));
	while (pq.size())
	{
		auto tope = pq.top();
		pq.pop();
		int cost, node, mask;
		tie(cost, node, mask) = tope;

		if (vis[mask][node])
			continue;
		vis[mask][node] = true;
		if (mask == 3)
			ret[node] = cost;

		for (i = 0; i < 4; i++)
		{
			if (i % 2 < mask % 2 || i / 2 < mask / 2)
				continue;
			for (auto x : adj[node])
			{
				pq.push(make_tuple(cost + x.second * (1 + (i % 2 > mask % 2) - (i / 2 > mask / 2)), x.first, i));
			}
		}
		// for (auto x : adj[node])
		// {
		// 	pq.push(make_tuple(cost + x.second, x.first, mask));
		// 	if ((mask & 1) == 0)
		// 		pq.push(make_tuple(cost, x.first, mask | 1));
		// 	if ((mask & 2) == 0)
		// 		pq.push(make_tuple(cost + 2 * x.second * 2, x.first, mask | 2));
		// 	if ((mask & 3) == 0)
		// 		pq.push(make_tuple(cost + x.second, x.first, mask | 3));
		// }
	}
	for (i = 2; i <= n; i++)
	{
		cout << ret[i] << " ";
	}
	cout << endl;
}