#include #include using namespace std; int n; unsigned int units[1 + 100][1 + 100] = { 0 }; unsigned int required[1 + 100] = { 0 }; int output[1 + 100] = { 0 }; void scan(int node, unsigned int unit) { required[node] += unit; --output[node]; if (output[node] > 0) { return; } bool generated = false; for (int previous = 0; previous <= n; ++previous) { if (units[previous][node] > 0) { scan(previous, required[node] * units[previous][node]); generated = true; } } if (generated) { required[node] = 0; } } int main() { int m; cin >> n >> m; vector p(m), q(m), r(m); for (int i = 0; i < m; ++i) { cin >> p[i] >> q[i] >> r[i]; } for (int i = 0; i < m; ++i) { units[p[i]][r[i]] = q[i]; ++output[p[i]]; } output[n] = 1; scan(n, 1); for (int i = 1; i <= n - 1; ++i) { cout << required[i] << endl; } return 0; }