#include <bits/stdc++.h>
using namespace std;

vector<pair<int, long long> > graph[100010];

typedef pair<long long, pair<int, int> > P;

long long dist[100010][2];

int main(){
    int n, m;
    cin >> n >> m;

    int a, b;
    long long c;
    for(int i = 0;i < m;i++){
        cin >> a >> b >> c;
        a--, b--;
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }

    dist[0][1] = 0;
    dist[0][0] = 0;
    for(int i = 1;i < n;i++){
        dist[i][0] = dist[i][1] = LLONG_MAX;
    }

    priority_queue<P, vector<P>, greater<P> > que;

    que.push(make_pair(0, make_pair(0, 1)));
    que.push(make_pair(0, make_pair(0, 0)));

    while(!que.empty()){
        long long cost = que.top().first;
        int idx = que.top().second.first;
        int tk = que.top().second.second;
        que.pop();

        for(int i = 0;i < graph[idx].size();i++){
            int next = graph[idx][i].first;
            long long ncost = graph[idx][i].second;
            if(cost + ncost < dist[next][tk]){
                dist[next][tk] = cost + ncost;
                que.push(make_pair(dist[next][tk], make_pair(next, tk)));
            }
            if(tk == 1 && cost < dist[next][0]){
                dist[next][0] = cost;
                que.push(make_pair(cost, make_pair(next, 0)));
            }
        }
    }

    for(int i = 0;i < n;i++){
        cout << dist[i][1] + dist[i][0] << endl;
    }

    return 0;
}