#include <bits/stdc++.h>
#define nmax 50002
#define oo 1e9
using namespace std;
int n,d[nmax],viz[nmax];
vector < pair<int, int> > L[nmax];
void citire()
{
ifstream fin("dijkstra.in");
int x,y,c,m;
fin >> n >> m;
while(m--)
{
fin >> x >> y >> c;
L[x].push_back({y,c});
L[y].push_back({x,c});
}
fin.close();
}
void afisare(int k)
{
ofstream fout("dijkstra.out");
int i;
for(i = 1; i <= n; i++)
if(i != k) fout << d[i] << " ";
fout.close();
}
void dijkstra(int k)
{
int j,nod;
for(j = 1; j <= n; j++)
d[j] = oo;
d[k] = 0;
priority_queue <int> q;
q.push(-k);
while(!q.empty())
{
nod = -q.top();
q.pop();
if(viz[nod] == 0)
{
viz[nod] = 1;
for(auto i : L[nod])
{
if(d[i.first] > d[nod] + i.second)
{
d[i.first] = d[nod] + i.second;
q.push(-i.first);
}
}
}
}
afisare(k);
}
int main()
{
citire();
dijkstra(1);
return 0;
}