import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int n = Integer.parseInt(stdin.next()); int m = Integer.parseInt(stdin.next()); Map> costs = new HashMap<>(); for (int i = 0; i < m; i++) { int a = Integer.parseInt(stdin.next()) - 1; int b = Integer.parseInt(stdin.next()) - 1; int c = Integer.parseInt(stdin.next()); costs.computeIfAbsent(a, unused -> new HashMap<>()).put(b, c); costs.computeIfAbsent(b, unused -> new HashMap<>()).put(a, c); } int[] d2 = new int[n * 2]; PriorityQueue q2 = new PriorityQueue<>(Comparator.comparing(i -> d2[i])); Arrays.fill(d2, Integer.MAX_VALUE); d2[n * 0 + 0] = 0; d2[n * 1 + 0] = 0; q2.add(n * 0 + 0); q2.add(n * 1 + 0); while (!q2.isEmpty()) { int u = q2.poll(); int x = u % n; boolean skipped = (u / n == 1); if (skipped) { for (int y : costs.getOrDefault(x, Collections.emptyMap()).keySet()) { int v = n * 1 + y; if (d2[u] + costs.get(x).get(y) < d2[v]) { d2[v] = d2[u] + costs.get(x).get(y); q2.add(v); } } } else { for (int y : costs.getOrDefault(x, Collections.emptyMap()).keySet()) { int v = n * 0 + y; if (d2[u] + costs.get(x).get(y) < d2[v]) { d2[v] = d2[u] + costs.get(x).get(y); q2.add(v); } } for (int y : costs.getOrDefault(x, Collections.emptyMap()).keySet()) { int v = n * 1 + y; if (d2[u] < d2[v]) { d2[v] = d2[u]; q2.add(v); } } } } for (int i = 0; i < n; i++) { System.out.println(d2[n * 0 + i] + d2[n * 1 + i]); } } }