import java.util.*; class B{ static Scanner s = new Scanner(System.in); public static void main(String[] args) { int size = Integer.parseInt(s.next()); int[][] step = new int[size][size]; long[] amount = new long[size]; boolean[] used = new boolean[size]; ArrayDeque deque = new ArrayDeque<>(); deque.add(size-1); for(int i=Integer.parseInt(s.next())-1;i>=0;--i) { int from = Integer.parseInt(s.next())-1, x = Integer.parseInt(s.next()), to = Integer.parseInt(s.next())-1; step[to][from]=x; used[to]=true; } while(!deque.isEmpty()) { int i = deque.pollFirst(); amount[size-1]=1; for(int j=0;j0) { amount[j] += step[i][j]*amount[i]; deque.addFirst(j); } } if(used[i]) amount[i]=0; } for(int i=0;i