#include struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance; #include #include #include template* = nullptr> struct modulo_matrix{ private: using m32 = Elem; public: int h; int w; std::vector elems; modulo_matrix(int new_h, int new_w){ h = new_h; w = new_w; elems.assign(h * w, 0); } modulo_matrix(const modulo_matrix&) = default; typename std::vector::iterator operator[](int y){ return elems.begin() + (y * w); } typename std::vector::const_iterator operator[](int y) const { return elems.begin() + (y * w); } static modulo_matrix identity(int idx){ auto res = modulo_matrix(idx, idx); for(int i = 0; i < idx; i++) res[i][i] = 1; return res; } modulo_matrix operator*(const modulo_matrix& r) const { assert(w == r.h); auto res = modulo_matrix(h, r.w); for (int i=0; i=i; k--) g[j][k] -= g[j][i] * g[i][k]; } return ans; } int rank() const { modulo_matrix g = *this; int y = 0; for (int i=0; iy; k--) g[j][k] -= g[j][i] * g[y][k]; y++; } return y; } }; #include using namespace std; using m32 = atcoder::static_modint<998244353>; using Matrix = modulo_matrix; int main() { int N,M; cin >> N >> M; vector>> A(M); vector>> B(M); for(int i=0; i> u >> v >> w; u--; v--; w--; A[i].push_back(make_pair(u, m32(1))); A[i].push_back(make_pair(v, m32(-1))); B[i].push_back(make_pair(v, m32(1))); B[i].push_back(make_pair(w, m32(-1))); } modulo_matrix G(N,N); m32 rng_r = 10000; m32 rng = 1; for(int i=0; i