import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final int M = sc.nextInt(); int[] in_degs = new int[N]; ArrayList> rev_adj = new ArrayList>(); for(int i = 0; i < N; i++){ rev_adj.add(new HashMap()); } for(int i = 0; i < M; i++){ final int P = sc.nextInt() - 1; final long Q = sc.nextLong(); final int R = sc.nextInt() - 1; in_degs[R]++; if(!rev_adj.get(P).containsKey(R)){ rev_adj.get(P).put(R, Q); }else{ rev_adj.get(P).put(R, Math.min(Q, rev_adj.get(P).get(R))); } } LinkedList queue = new LinkedList(); long[][] comps = new long[N][N]; for(int i = 0; i < N; i++){ if(in_degs[i] != 0){ continue; } comps[i][i] = 1; queue.add(i); } while(!queue.isEmpty()){ final int node = queue.poll(); for(final Entry entry : rev_adj.get(node).entrySet()){ final int from = entry.getKey(); final long value = entry.getValue(); for(int i = 0; i < N; i++){ comps[from][i] += value * comps[node][i]; } in_degs[from]--; if(in_degs[from] == 0){ queue.add(from); } } } for(int i = 0; i < N - 1; i++){ System.out.println(comps[N - 1][i]); } } }