#include using namespace std; using ll = long long; const int maxn = 100005; const int mod = 998244353; int a[maxn],b[maxn],c[maxn]; int parent[maxn],dist[maxn]; int Find(int x){ if(parent[x] != x){ dist[x] ^= dist[ parent[x] ]; parent[x] = Find(parent[x]); } return parent[x]; } int comp; bool Union(int x, int y, int c){ x = Find(x); y = Find(y); if(x != y){ --comp; dist[y] = (dist[x] ^ dist[y] ^ c); parent[y] = x; return true; } bool ok = (dist[y] ^ dist[x]) == c; return ok; } int main(){ int N,Q; cin >> N >> Q; for(int i = 0;i < Q;++i){ cin >> a[i] >> b[i] >> c[i]; } for(int i = 1;i <= N;++i){ parent[i] = i; dist[i] = 0; } comp = N; ll ans = 1; for(int i = 0;i < Q;++i){ if(!Union(a[i], b[i], c[i])){ ans = 0; break; } } if(ans){ for(int i = 1;i <= comp;++i){ ans = ans * 2 % mod; } } cout << ans << endl; return 0; }