import java.util.*; public class Main { static ArrayList> graph = new ArrayList<>(); static ArrayList> result = new ArrayList<>(); public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); for (int i = 0; i < n; i++) { graph.add(new HashMap<>()); result.add(new HashMap<>()); } for (int i = 0; i < m; i++) { int source = sc.nextInt() - 1; int count = sc.nextInt(); graph.get(sc.nextInt() - 1).put(source, count); } HashMap ans = search(n - 1); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n - 1; i++) { if (ans.containsKey(i)) { sb.append(ans.get(i)); } else { sb.append("0"); } sb.append("\n"); } System.out.print(sb); } static HashMap search(int idx) { HashMap map = result.get(idx); if (map.size() > 0) { return map; } if (graph.get(idx).size() == 0) { map.put(idx, 1); return map; } for (Map.Entry entry1 : graph.get(idx).entrySet()) { HashMap parts = search(entry1.getKey()); for (Map.Entry entry2 : parts.entrySet()) { int key = entry2.getKey(); int value = entry1.getValue() * entry2.getValue(); if (map.containsKey(key)) { map.put(key, map.get(key) + value); } else { map.put(key, value); } } } return map; } }