#include using namespace std; #include using namespace atcoder; using mint = modint998244353; int main() { int N, Q; cin >> N >> Q; vector>> G(N); for (int i = 0; i < Q; i++) { int a, b, c; cin >> a >> b >> c; a--, b--; G.at(a).push_back({b, c}); G.at(b).push_back({a, c}); } mint ans = 1; vector colors(N, -1); auto dfs = [&](auto self, int v) -> void { for (auto [nv, d] : G.at(v)) { int new_color = colors.at(v) ^ d; if (colors.at(nv) == -1) { colors.at(nv) = new_color; self(self, nv); } else if (colors.at(nv) != new_color) ans *= 0; } }; for (int v = 0; v < N; v++) { if (colors.at(v) == -1) { ans *= 2; colors.at(v) = 0; dfs(dfs, v); } } cout << ans.val() << endl; }