#include <fstream>
#include <queue>
using namespace std;
ifstream in("dijkstra.in");
ofstream out("dijkstra.out");
priority_queue< pair<int,int> >pq;
vector< pair<int,int> >v[50005];
int minn[50005];
bool ok[50005];
void dijkstra()
{
while(!pq.empty())
{
pair<int,int> a=pq.top();
pq.pop();
a.first=-a.first;
ok[a.first]=true;
for(int i=0; i<v[a.first].size(); i++)
{
int x=a.first;
int y=v[a.first][i].first;
if(ok[y]==false && minn[y]>a.second+v[a.first][i].second)
{
minn[y]=a.second+v[a.first][i].second;
pq.push({-y,a.second+v[a.first][i].second});
}
}
}
}
int main()
{
pq.push({-1,0});
int n,m;
in>>n>>m;
for(int i=0; i<m; i++)
{
int x,y,z;
in>>x>>y>>z;
v[x].push_back({y,z});
v[y].push_back({x,z});
}
for(int i=2; i<=n; i++)
minn[i]=2100000000;
dijkstra();
for(int i=2; i<=n; i++)
{
if(minn[i]==2100000000)
out << 0 << " ";
else
out << minn[i] << " ";
}
}