#include #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; constexpr int INF = 1e9; constexpr ll LINF = 1e18; string YesNo(bool cond) { return cond ? "Yes" : "No"; } string YESNO(bool cond) { return cond ? "YES" : "NO"; } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; } template T bisect(T ok, T ng, const F& f) { while (abs(ok - ng) > 1) { T mid = min(ok, ng) + (abs(ok - ng) >> 1); (f(mid) ? ok : ng) = mid; } return ok; } template T bisect_double(T ok, T ng, const F& f, int iter = 100) { while (iter--) { T mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template vector make_vec(size_t a) { return vector(a); } template auto make_vec(size_t a, Ts... ts) { return vector(ts...))>(a, make_vec(ts...)); } template istream& operator>>(istream& is, vector& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } #include using mint = atcoder::modint998244353; int main() { int n, m; cin >> n >> m; vector>> g(n); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--, b--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } vector f(n, -1); queue q; mint ans = 1; rep(i, n) if (f[i] == -1) { bool ok = true; f[i] = 0; q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); for (auto [v, c] : g[u]) { if (f[v] == -1) { f[v] = f[u] ^ c; q.push(v); } ok &= f[v] == (f[u] ^ c); } } if (ok) { ans *= 2; } else { ans *= 0; } } cout << ans.val() << '\n'; }