#include #include #include using namespace std; using mint = atcoder::modint998244353; class potentialized_unionfind{ /* Copyright (c) 2021 0214sh7 https://github.com/0214sh7/library/ */ private: std::vector UF,rank,pot; vector history; public: void init(int N){ UF.clear(); rank.clear(); for(int i=0;isync_with_stdio(0); int N, Q; cin >> N >> Q; potentialized_unionfind uf(N); const mint all = mint{2}.pow(N), inv2 = 998244354 / 2; mint ans = all; while(Q--) { int t; cin >> t; if(t == 3) { uf.clear(); ans = all; } else { int u, v; cin >> u >> v; u--; v--; t--; if(uf.same(u, v)) { if(uf.diff(u, v) != t) ans = 0; } else { uf.unite(u, v, t); ans *= inv2; } } cout << ans.val() << '\n'; } }