// need #include #include // data structure #include //#include #include #include #include #include #include #include #include //#include //#include #include #include #include //#include #include // stream //#include //#include //#include // etc #include #include #include //#include #include #include #include #define INIT std::ios::sync_with_stdio(false);std::cin.tie(0); #define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template void MACRO_VAR_Scan(T& t) { std::cin >> t; } templatevoid MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC_ROW(type, n, ...)std::vector __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int i=0; i void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } templatevoid MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; } templatevoid MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define OUT(d) std::cout< c(n);for(auto& i:c)std::cin>>i; #define MAT(type, c, m, n) std::vector> c(m, std::vector(n));for(auto& r:c)for(auto& i:r)std::cin>>i; #define ALL(a) (a).begin(),(a).end() #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i) #define REP(i, n) for(int i=0;i=0;--i) #define FORLL(i, a, b) for(ll i=ll(a);i=ll(a);--i) #define REPLL(i, n) for(ll i=0;i=0;--i) #define PAIR std::pair #define PAIRLL std::pair #define IN(a, x, b) (a<=x && x tmp(a);std::cerr << #a << "\t:";for(int i=0; i(a.size()); ++i){std::cerr << tmp.front() << "\n";tmp.pop();}std::cerr << "\n";} template inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; } template inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; } #define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]" #define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;} void CHECKTIME(std::function f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast((end - start)).count(); std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n"; } //#define int ll using ll = long long; using ull = unsigned long long; constexpr int INFINT = 1 << 30; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double EPS = 1e-7; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template class Matrix { private: std::valarray> mat; public: Matrix(size_t m = 0, size_t n = 0, T init = 0) { if (n == 0) n = m; mat.resize(m); for (size_t i = 0; i < m; ++i) mat[i].resize(n, init); } Matrix(std::valarray> a) { mat = a; } Matrix init(size_t m = 0, size_t n = 0, T init = 0) { if (n == 0) n = m; mat.resize(m); for (size_t i = 0; i < m; ++i) mat[i].resize(n, init); return *this; } std::valarray& operator[](size_t i) { return mat[i]; } const std::valarray& operator[](size_t i) const { return mat[i]; } Matrix& operator=(const Matrix& r) { for (size_t i = 0; i < mat.size(); ++i) mat[i] = r[i]; return *this; } Matrix operator+() const { return mat; } Matrix operator-() const { Matrix res(mat.size()); for (size_t i = 0; i < mat.size(); ++i) res[i] = -mat[i]; return res; } Matrix& operator+=(const Matrix& r) { for (size_t i = 0; i < mat.size(); ++i) mat[i] += r[i]; return *this; } Matrix& operator+=(const T& x) { for (size_t i = 0; i < mat.size(); ++i) mat[i] += x; return *this; } Matrix& operator-=(const Matrix& r) { return *this += -r; } Matrix& operator-=(const T& x) { return *this += -x; } Matrix& operator*=(const Matrix& r) { // O(N^3) Matrix res(mat.size(), r[0].size()); for (size_t i = 0; i < mat.size(); ++i) { for (size_t j = 0; j < r[0].size(); ++j) { for (size_t k = 0; k < mat[0].size(); ++k) { res[i][j] += mat[i][k] * r[k][j]; } } } return *this = res; } Matrix& operator*=(const T& x) { for (size_t i = 0; i < mat.size(); ++i) mat[i] *= x; return *this; } Matrix& operator^=(ll p) { // O(N^3 logP) Matrix res(mat.size()); for (size_t i = 0; i < mat.size(); ++i) res[i][i] = 1; while (p) { if (p & 1) res *= (*this); (*this) *= (*this); p >>= 1; } for (size_t i = 0; i < mat.size(); ++i) mat[i] = res[i]; return *this; } Matrix operator+(const Matrix& r) const { Matrix res(mat); return res += r; } Matrix operator-(const Matrix& r) const { Matrix res(mat); return res -= r; } Matrix operator*(const Matrix& r) const { Matrix res(mat); return res *= r; } Matrix operator*(const T& r) const { Matrix res(mat); return res *= r; } Matrix operator^(const int& p) const { Matrix res(mat); return res ^= p; } Matrix t() const { Matrix res(mat[0].size(), mat.size(), 0); for (size_t i = 0; i < mat[0].size(); ++i) { for (size_t j = 0; j < mat.size(); ++j) { res[i][j] = mat[j][i]; } } return res; } double det() const { TRY(mat.size() != mat[0].size(), "Matrix is not square."); Matrix a(mat.size()); for (size_t i = 0; i < mat.size(); ++i) { for (size_t j = 0; j < mat.size(); ++j) { a[i][j] = static_cast(mat[i][j]); } } double d = 1; for (int i = 0; i < mat.size(); ++i) { int pivot = i; for (size_t j = i + 1; j < mat.size(); ++j) { if (std::abs(a[j][i]) > std::abs(a[pivot][i])) pivot = j; } std::swap(a[pivot], a[i]); d *= a[i][i] * ((i != pivot) ? -1 : 1); if (std::abs(a[i][i]) < EPS) break; for (size_t j = i + 1; j < mat.size(); ++j) { for (int k = mat.size() - 1; k >= i; --k) { a[j][k] -= a[i][k] * a[j][i] / a[i][i]; } } } return d; } T tr() const { T res = 0; for (size_t i = 0; i < mat.size(); ++i) { res += mat[i][i]; } return res; } size_t rank() const { Matrix a(mat.size()); for (size_t i = 0; i < mat.size(); ++i) { for (size_t j = 0; j < mat.size(); ++j) { a[i][j] = static_cast(mat[i][j]); } } size_t r = 0; for (int i = 0; r < static_cast(mat.size()) && i < static_cast(mat[0].size()); ++i) { int pivot = r; for (size_t j = r + 1; j < mat.size(); ++j) { if (std::abs(a[j][i]) > std::abs(a[pivot][i])) pivot = j; } std::swap(a[pivot], a[r]); if (std::abs(a[r][i]) < EPS) continue; for (int k = mat[0].size() - 1; k >= i; --k) { a[r][k] /= a[r][i]; } for (size_t j = r + 1; j < mat.size(); ++j) { for (size_t k = i; k < mat[0].size(); ++k) { a[j][k] -= a[r][k] * a[j][i]; } } ++r; } return r; } static Matrix getUnit(size_t n) { Matrix res(n, n, 0); for (size_t i = 0; i < n; ++i) res[i][i] = 1; return res; } void show() const { for (const auto& r : mat) { for (const auto & x : r) { std::cerr << x << "\t"; } std::cerr << std::endl; } } }; signed main() { INIT; VAR(int, n, m); VEC_ROW(int, m, a, b, c); std::vector sum(n); REP(i, m) { sum[a[i]] += c[i]; } Matrix mat(n, n); REP(i, m) { assert(sum[a[i]] != 0); mat[a[i]][b[i]] = 1.*c[i]/sum[a[i]]; } mat ^= 100; mat *= 10; REP(i, n) { double ans = 0; REP(j, n) ans += mat[j][i]; OUT(ans)BR; } return 0; }