#include using namespace std; #define REP(i,a,b) for(int i=a;i G[110]; typedef pair Pii; int N, M; int ans[110]; void get(int st) { queue q1, q2; q1.push(st); q2.push(1); while(!q1.empty()) { int pos = q1.front(); q1.pop(); int cost = q2.front(); q2.pop(); ans[pos] += cost; rep(i, G[pos].size()) { q1.push(G[pos][i].dst); q2.push(G[pos][i].cost*cost); } } } int main() { cin >> N >> M; bool isntLast[110] = {}; rep(i, M) { int p, q, r; cin >> p >> q >> r; p --, r --; G[r].push_back(Edge(p, q)); isntLast[r] = 1; } get(N-1); rep(i, N-1) { if(isntLast[i]) cout << 0 << endl; else printf("%d\n", ans[i]); } return 0; }