#include <fstream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
vector<int> dijkstra(int node , vector<vector<pair<int , int>>>& edges ,vector <int>& costs)
{
priority_queue<pair<int ,int>>pq;
pq.push(make_pair(0 , node));
int parent , costfrom1tonode;
pair<int , int>current;
costs[node] = 0;
while(!pq.empty())
{
current = pq.top();
parent = current.second;
costfrom1tonode = -current.first;
pq.pop();
if(costfrom1tonode > costs[parent])
continue;
for(pair<int,int> kid : edges[parent])
{
int kidindex,costfromparenttokid;
kidindex = kid.first;
costfromparenttokid = kid.second;
if(costs[kidindex] > costs[parent] + costfromparenttokid)
{
costs[kidindex] = costs[parent] + costfromparenttokid ;
pq.push(make_pair(-costs[kidindex], kidindex));
}
}
}
return costs;
}
int main()
{
int n , m ,a , b , cost;
fin >> n >> m;
vector<vector<pair<int ,int>>>edges(n + 1);
vector<int> costs(n + 1 , INT_MAX);
for(int i = 1 ; i <= m;i++)
{
fin >> a >> b >> cost;
edges[a].push_back(make_pair(b , cost));
}
vector<int> minpaths = dijkstra( 1 , edges , costs);
for(int i = 2; i <= n; i++)
{
if(minpaths[i] != INT_MAX)
{
fout << minpaths[i] << '\n';
}
else
fout << "0" <<'\n';
}
return 0;
}