#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 2e5 + 5;
int ver[maxn], edge[maxn], Next[maxn], head[maxn], d[maxn];
int tot, n, m;
bool v[maxn];
void add(int x, int y, int z) {
ver[++tot] = y;
edge[tot] = z;
Next[tot] = head[x];
head[x] = tot;
}
queue <int>q;
void spfa() {
memset(v, 0, sizeof v);
memset(d, 0x3f, sizeof d);
d[1] = 0; v[1] = 1;
q.push(1);
while (q.size()) {
int x = q.front(); q.pop();
v[x] = 0;
for (int i = head[x]; i; i = Next[i]) {
int y = ver[i], z = edge[i];
if (d[y] > d[x] + z) {
d[y] = d[x] + z;
if (!v[y]) q.push(y), v[y] = 1;
}
}
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b, c; cin >> a >> b >> c;
add(a, b, c);
}
spfa();
for (int i = 1; i <= n; i++) cout << d[i] << endl;
return 0;
}