#include <fstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
const int INF = 0x3f3f3f3f;
int N, M;
int D[50005];
vector<pair<int, int> > V[50005];
queue<pair<int, int> > Q;
void bellman()
{
memset(D, INF, sizeof(D));
D[1] = 0;
Q.push(make_pair(1, 0));
while (!Q.empty())
{
int now = Q.front().first;
int nowc = Q.front().second;
Q.pop();
for (vector<pair<int, int> >::iterator it = V[now].begin(); it != V[now].end(); ++it)
{
if (nowc + it->second < D[it->first])
{
D[it->first] = nowc + it->second;
Q.push(make_pair(it->first, nowc + it->second));
}
}
}
}
int main()
{
fin >> N >> M;
for (int i = 1, nod1, nod2, cost; i <= M; ++i)
{
fin >> nod1 >> nod2 >> cost;
V[nod1].push_back(make_pair(nod2, cost));
}
bellman();
for (int i = 2; i <= N; ++i)
{
if (D[i] == INF)
fout << 0 << ' ';
else
fout << D[i] << ' ';
}
fout << '\n';
fin.close();
fout.close();
return 0;
}