import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); ArrayList[] graph = new ArrayList[n]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList<>(); } for (int i = 0; i < m; i++) { String[] line = br.readLine().split(" ", 3); int a = Integer.parseInt(line[0]) - 1; int b = Integer.parseInt(line[1]) - 1; int c = Integer.parseInt(line[2]); graph[a].add(new Path(b, c)); graph[b].add(new Path(a, c)); } long[] visited = new long[n]; long[] tickets = new long[n]; Arrays.fill(visited, Long.MAX_VALUE); Arrays.fill(tickets, Long.MAX_VALUE); PriorityQueue queue = new PriorityQueue<>(); PriorityQueue next = new PriorityQueue<>(); tickets[0] = 0; queue.add(new Path(0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (visited[p.idx] <= p.value) { continue; } visited[p.idx] = p.value; for (Path q : graph[p.idx]) { queue.add(new Path(q.idx, p.value + q.value)); next.add(new Path(q.idx, p.value)); } } while (next.size() > 0) { Path p = next.poll(); if (tickets[p.idx] <= p.value) { continue; } tickets[p.idx] = p.value; for (Path q : graph[p.idx]) { next.add(new Path(q.idx, p.value + q.value)); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(visited[i] + tickets[i]).append("\n"); } System.out.print(sb); } static class Path implements Comparable { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { if (value == another.value) { return 0; } else if (value < another.value) { return -1; } else { return 1; } } } }