// ランクを M 回求める TLE になってほしい // 乱択も一回だけ #include #include #include #include #include #include #include #include using namespace std; #include // Try to calculate inverse of M and return rank of M (destructive) template int inverse_matrix(std::vector> &M) { const int N = M.size(); assert(N and M[0].size() == M.size()); std::vector> ret(N, std::vector(N)); for (int i = 0; i < N; ++i) ret[i][i] = 1; int rank = 0; for (int i = 0; i < N; ++i) { int ti = i; while (ti < N and M[ti][i] == 0) ti++; if (ti == N) { continue; } ++rank; ret[i].swap(ret[ti]), M[i].swap(M[ti]); T inv = T(1) / M[i][i]; for (int j = 0; j < N; ++j) ret[i][j] *= inv; for (int j = i + 1; j < N; ++j) M[i][j] *= inv; for (int h = 0; h < N; ++h) { if (i == h) continue; const T c = -M[h][i]; for (int j = 0; j < N; ++j) ret[h][j] += ret[i][j] * c; for (int j = i + 1; j < N; ++j) M[h][j] += M[i][j] * c; } } M = ret; return rank; } template vector solve(int N, vector, pair>> bcs) { std::mt19937 mt(std::chrono::steady_clock::now().time_since_epoch().count()); std::uniform_int_distribution rng(0, ModInt::mod() - 1); std::vector> M(N, std::vector(N)), Minv; vector ret; for (auto [ab, cd] : bcs) { auto x = rng(mt); auto [a, b] = ab; auto [c, d] = cd; M[a][c] += x; M[a][d] -= x; M[b][c] -= x; M[b][d] += x; M[c][a] -= x; M[d][a] += x; M[c][b] += x; M[d][b] -= x; Minv = M; ret.push_back(inverse_matrix(Minv) / 2); } return ret; } int main() { int N, M; cin >> N >> M; vector, pair>> edges; while (M--) { int u, v, w; cin >> u >> v >> w; u--, v--, w--; edges.push_back({{u, w}, {v, w}}); } auto ret = solve>(N, edges); for (auto x : ret) cout << x << '\n'; }