import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int parts = sc.nextInt() - 1; int count = sc.nextInt(); int product = sc.nextInt() - 1; graph.get(product).put(parts, count); } ArrayDeque deq = new ArrayDeque<>(); deq.add(new Path(n - 1, 1)); long[] ans = new long[n]; while (deq.size() > 0) { Path p = deq.poll(); if (graph.get(p.idx).size() == 0) { ans[p.idx] += p.value; } else { for (int x : graph.get(p.idx).keySet()) { deq.add(new Path(x, p.value * graph.get(p.idx).get(x))); } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n - 1; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } static class Path { int idx; long value; public Path(int idx, long value) { this.idx = idx; this.value = value; } } }