#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <random>
#include <assert.h>
using namespace std;
const string file = "dijkstra";
const string infile = file + ".in";
const string outfile = file + ".out";
const int INF = 0x3f3f3f3f;
//#define ONLINE_JUDGE
int main()
{
#ifdef ONLINE_JUDGE
ostream &fout = cout;
istream &fin = cin;
#else
fstream fin(infile.c_str(), ios::in);
fstream fout(outfile.c_str(), ios::out);
#endif
int N, M;
fin >> N >> M;
vector<vector<pair<int, int> > > G(N + 1);
for(int i = 0; i < M; i++)
{
int x, y, c;
fin >> x >> y >> c;
G[x].push_back(make_pair(y, c));
}
vector<int> dist(N + 1, INF);
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > heap;
dist[1] = 0;
heap.push(make_pair(0, 1));
while(heap.empty() == false)
{
pair<int, int> c = heap.top();
heap.pop();
int x = c.second;
int d = c.first;
if(dist[x] != d)
continue;
for(vector<pair<int, int> >::iterator itr = G[x].begin();
itr != G[x].end();
itr++)
{
int newDist = d + itr->second;
int nod = itr->first;
if(dist[nod] > newDist)
{
dist[nod] = newDist;
heap.push(make_pair(dist[nod], nod));
}
}
}
for(int i = 2; i <= N; i++)
{
fout << (dist[i] == INF ? 0 : dist[i]) << " ";
}
fout << "\n";
#ifdef ONLINE_JUDGE
#else
fout.close();
fin.close();
#endif
}