#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <queue>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> adj(n+1, vector<pair<int, int>>());
for (int i = 0; i < m; i++)
{
int a, b, w;
cin >> a >> b >> w;
adj[a].push_back({b, w});
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
vector<long long> dist(adj.size(), LLONG_MAX);
vector<int> visited(adj.size(), false);
pq.push({0, 1});
dist[1] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
if (visited[u])
continue;
visited[u] = true;
// Iterate through all adjacent vertices of the current vertex
for (auto &neighbor : adj[u]) {
int v = neighbor.first;
int weight = neighbor.second;
// If a shorter path to v is found
if (!visited[v] && dist[v] > dist[u] + weight) {
// Update distance and push new distance to the priority queue
dist[v] = dist[u] + weight;
pq.push({dist[v], v});
}
}
}
for (int i = 1; i < adj.size(); i++)
cout << dist[i] << " ";
}