#include #include #include #include using namespace std; typedef long long LL; typedef vector LLVec; struct Node { LL count; LLVec dep_type; LLVec dep_count; Node() : count(0) { } void request(LL c); }; Node nodes[100]; void Node::request(LL c) { if (dep_type.empty()) { count += c; } else { for (LL i = 0; i < dep_type.size(); ++i) { nodes[dep_type[i]].request(c * dep_count[i]); } } }; int main(int argc, char *argv[]) { string s; getline(cin, s); int N = atoi(s.c_str()); getline(cin, s); int M = atoi(s.c_str()); for (int i = 0; i < M; ++i) { getline(cin, s); stringstream ss(s); int P, Q, R; ss >> P >> Q >> R; nodes[R - 1].dep_type.push_back(P - 1); nodes[R - 1].dep_count.push_back(Q); } nodes[N - 1].request(1); for (int i = 0; i < N - 1; ++i) { cout << nodes[i].count << endl; } return 0; }