#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define MAX_N 510 #define PI 3.141592653589 #define ESP 1e-20 #define BS 10 #define MOD 1000000007 #define ZERO 10001 #define YJSNPI 810 #define INF (1LL << 50) #define ADD(a, b) a = (a + (ll)b) % MOD #define MUL(a, b) a = (a * (ll)b) % MOD #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) using namespace std; typedef long long ll; typedef pair pi; struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} }; int N, M; vector E[110]; vector rE[110]; int ans[110]; int dp[110]; vector vs; void dfs(int v) { bool ok = false; for(int i = 0; i < rE[v].size(); i++) { dfs(rE[v][i].to); ok = true; } if(!ok) vs.push_back(v); } int loop(int v) { if(v == N - 1) return 1; if(dp[v] != -1) return dp[v]; int res = 0; for(int i = 0; i < E[v].size(); i++) { res += loop(E[v][i].to) * E[v][i].cost; } return res; } int main() { scanf("%d%d", &N, &M); for(int i = 0; i < M; i++) { int from, cost, to; scanf("%d%d%d", &from, &cost, &to); from--; to--; E[from].push_back(edge(to, cost)); rE[to].push_back(edge(from, cost)); } dfs(N - 1); memset(dp, -1, sizeof(dp)); for(int i = 0; i < vs.size(); i++) { ans[vs[i]] = loop(vs[i]); } for(int i = 0; i < N - 1; i++) { printf("%d\n", ans[i]); } }