#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define INF_MIN 100000000 #define INF 1145141919 #define INF_MAX 2147483647 #define LL_MAX 9223372036854775807 #define EPS 1e-10 #define PI acos(-1) #define LL long long using namespace std; typedef pair P; #define MAX_N 101 #define MAX_M 1501 LL N, M; vector

Edge[MAX_N]; // first:次の番号 second: 個数 LL memo[MAX_N]; LL solve(int pos){ if(memo[pos] != 0) return memo[pos]; LL ret = 0; for(int i = 0; i < Edge[pos].size(); i++){ ret += solve(Edge[pos][i].first) * Edge[pos][i].second; } return memo[pos] = ret; } int main(){ cin >> N; cin >> M; memset(memo, 0, sizeof(memo)); memo[N] = 1; map material; for(int i = 0; i < M; i++){ LL p, q, r; cin >> p >> q >> r; Edge[p].push_back(P(r, q)); material[r] = true; } for(int i = 1; i < N; i++){ if(material[i]) cout << 0 << endl; else cout << solve(i) << endl; } return 0; }