#define _CRT_SECURE_NO_WARNINGS //#define _GLIBCXX_DEBUG #include using namespace std; typedef long long ll; typedef vector vi; typedef vector vvi; typedef pair pii; #define all(c) (c).begin(), (c).end() #define loop(i,a,b) for(ll i=a; i ostream & operator<<(ostream & os, vector const &); template typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple const &){} template typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple const & t){ os << (n==0?"":" ") << get(t); _ot(os, t); } template ostream & operator<<(ostream & os, tuple const & t){ _ot<0>(os, t); return os; } template ostream & operator<<(ostream & os, pair const & p){ return os << "(" << p.first << ", " << p.second << ") "; } template ostream & operator<<(ostream & os, vector const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; } #ifdef DEBUG #define dump(...) (cerr<<#__VA_ARGS__<<" = "<> n >> m){ rep(i,n) rep(j,n) g[i][j] = 0; rep(i,n) use[i] = 0; use[n-1] = 1; rep(i,m){ int x,y,z; cin >> x >> y >> z; x--; z--; g[x][z] = y; } while(1){ bool finish = true; rep(i,n){ int out = 0, in = 0; rep(j,n) if(g[i][j]) out++; rep(j,n) if(g[j][i]) in++; if(out==0 && in > 0){ finish = false; rep(j,n){ if(g[j][i]){ use[j] += use[i]*g[j][i]; g[j][i] = 0; } } use[i] = 0; } } if(finish) break; } rep(i,n-1){ cout << use[i] << endl; } // this_thread::sleep_for(chrono::seconds(1<<20)); } }