#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
const int N = 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_MAX / 2;
d[s] = 0;
int cnt = 0;
queue<int, vector<int>> q;
q.push(0);
while (q.size()) {
int v = q.front();
q.pop();
forn(i, c[v].size()) {
cnt++;
if (relax(d[c[v][i]], d[v] + w[v][i]))
q.push(c[v][i]);
}
}
fprintf(stderr, "cnt = %.2f\n", (double)cnt / m);
forn(i, n)
printf("%d ", d[i]);
return 0;
}