#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
std::vector<std::vector<std::pair<int,int>>> graf;
std::vector<int> dist;
void dijkstra(int node){
std::priority_queue<std::pair<int,int> , vector<std::pair<int,int>> , greater<std::pair<int,int>>> q;
q.push({0,node});
dist[node]=0;
while(!q.empty()){
int d = q.top().first;
int u = q.top().second;
q.pop();
if(d>dist[u])
continue;
for(auto [v,c]:graf[u]){
if(dist[u]+c<dist[v]){
dist[v]=dist[u]+c;
q.push({dist[v],v});}
}
}
}
const int INF = 1e9;
int main() {
ifstream fin("dijkstra.in");
ofstream fout("dijkstra.out");
int n, m;
fin >> n >> m;
graf.resize(n + 1);
dist.resize(n + 1, INF);
for (int i = 0; i < m; i++) {
int a, b, c;
fin >> a >> b >> c;
graf[a].push_back({b, c});
}
dijkstra(1);
for (int i = 2; i <= n; i++) {
if (dist[i] == INF)
fout <<0<< ' ';
else
fout<<dist[i] <<' ';
}
fout <<'\n';
return 0;
}