#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int N = (int)1e5;

int n, m, s = 0, d[N];
vector <int> c[N], w[N];

bool relax( int &a, int b )
{
  if (a <= b)
    return 0;
  a = b;
  return 1;
}

int main()
{
  scanf("%d%d", &n, &m);
  forn(i, m)
  {
    int a, b, x;
    scanf("%d%d%d", &a, &b, &x);
    c[a].push_back(b);
    w[a].push_back(x);
  }

  forn(i, n)
    d[i] = (int)2e9;
  d[s] = 0;

  int cnt = 0;
  for (int run = 1; run ; cnt++)
  {
    run = 0;
    forn(v, n)
      forn(i, c[v].size())
        if (relax(d[c[v][i]], d[v] + w[v][i]))
          run = 1;
  }
  fprintf(stderr, "cnt = %d\n", cnt);
  forn(i, n)
    printf("%d ", d[i]);
  return 0;
}