#include <bits/stdc++.h>
using namespace std;
ifstream f("dijkstra.in");
ofstream g("dijkstra.out");
const int NMAX=50001;
int N, D[NMAX];
vector<pair<int,int>> G[NMAX];
bool Visited[NMAX];
struct cmp { bool operator () (int x,int y) {return D[x]<D[y];} };
priority_queue<int,vector<int>,cmp> Q;
void Dijkstra(int start)
{
for(int i=1;i<=N;D[i++]=INT_MAX); D[start]=0;
Q.push(start),Visited[start]=1;
while(!Q.empty())
{
int x=Q.top();
Q.pop(), Visited[x]=false;
for(auto n:G[x])
{
int y=n.first, c=n.second;
if(D[x]+c<D[y])
{
D[y]=D[x]+c;
if(!Visited[y])
Q.push(y), Visited[y]=true;
}
}
}
}
int main()
{
f>>N;
for(int M=(f>>M,M),x,y,c;f>>x>>y>>c;G[x].push_back(make_pair(y,c)));
Dijkstra(1);
for(int i=2;i<=N;i++) cout<<D[i]<<' ';
return 0;
}