#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const long long INF = 100000000;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edge(101, vector<int>(0));
  vector<vector<int>> L(101, vector<int>(101));
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a].push_back(b);
    edge[b].push_back(a);
    L[a][b] = c;
    L[b][a] = c;
  }
  int i = 1;
  priority_queue<P, vector<P>, greater<P>> pq;
  vector<int> dist(N + 1, INF);
  dist[0] = 0;
  dist[i] = 0;
  pq.push(make_pair(dist[i], i));
  while (!pq.empty()) {
    P p = pq.top();
    pq.pop();
    int v = p.second;
    for (int u : edge[v]) {
      if (dist[v] + L[v][u] < dist[u]) {
        dist[u] = dist[v] + L[v][u];
        pq.push(make_pair(dist[u], u));
      }
    }
  }
  for (int j = 0; j < N + 1; j++) {
    cout << dist[j] << endl;
  }
}
