#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1e9 + 7; using ld = long double; using ll = long long; using ull = unsigned long long; template using pq = priority_queue; template using pqg = priority_queue, greater>; template inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return 1; } return 0; } template inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return 1; } return 0; } template auto min(const T& a) { *min_elemenet(all(a)); } template auto max(const T& a) { *max_elemenet(all(a)); } // const ll MOD = 1e9 + 7; const ll INF = 1 << 30; const ll INFLL = 1LL << 60; const ld EPS = 1e-9; const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1}; const ll dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; #define all(v) begin(v), end(v) int n, m; vector>> G; vector used; vector> memo; map dp(int v) { if (used[v]) return memo[v]; used[v] = true; if (G[v].empty()) return { { v, 1 } }; map &ret = memo[v]; for (auto& [to, cost] : G[v]) { for (auto& [material, num] : dp(to)) { ret[material] += num * cost; } } return ret; } int main(void) { cin >> n >> m; G.resize(n); memo.resize(n); used.assign(n, 0); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; G[c - 1].push_back({a - 1, b}); } auto ret = dp(n - 1); for (int i = 0; i < n - 1; ++i) { cout << ret[i] << endl; } return 0; }