/* -*- coding: utf-8 -*- * * 30.cc: No.30 たこやき工場 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100; /* typedef */ typedef vector vi; typedef pair pii; typedef vector vpii; /* global variables */ int n; vpii nbrs[MAX_N]; vi pvs[MAX_N]; /* subroutines */ void rec(int u) { if (pvs[u].size() > 0) return; pvs[u].assign(n, 0); vpii &nbru = nbrs[u]; if (nbru.size() == 0) { pvs[u][u] = 1; return; } for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int &v = vit->first, &c = vit->second; rec(v); for (int i = 0; i < n; i++) pvs[u][i] += pvs[v][i] * c; } } /* main */ int main() { int m; cin >> n >> m; for (int i = 0; i < m; i++) { int pi, qi, ri; cin >> pi >> qi >> ri; pi--, ri--; nbrs[ri].push_back(pii(pi, qi)); } rec(n - 1); for (int i = 0; i < n - 1; i++) printf("%d\n", pvs[n - 1][i]); return 0; }