#include <iostream>
#include <queue>
#include <vector>
#define NMAX 50005
#define INF ((1 << 30) - 1)
using namespace std;
typedef pair<int, int> pii;
int n, m, ans[NMAX];
bool v[NMAX];
vector<pii> adj[NMAX];
priority_queue<pii, vector<pii>, greater<pii> > pq;
void dij(const int SN = 1) {
ans[SN] = 0;
pq.push({0, SN});
while(!pq.empty()) {
const int crt = pq.top().second;
pq.pop();
if(v[crt]) continue;
v[crt] = 1;
for(const auto &el : adj[crt]) {
const int ncrt = el.first;
if(ans[ncrt] > ans[crt] + el.second) {
ans[ncrt] = ans[crt] + el.second;
pq.push({ans[ncrt], ncrt});
}
}
}
}
int main()
{
freopen("dijkstra.in", "r", stdin);
freopen("dijkstra.out", "w", stdout);
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
ans[i] = INF;
for(int x, y, z; m; --m) {
scanf("%d%d%d", &x, &y, &z);
adj[x].push_back({y, z});
}
dij();
for(int i = 2; i <= n; ++i) printf("%d ", (ans[i] == INF ? 0 : ans[i]));
return 0;
}