from collections import deque MOD = 998244353 n, q = map(int, input().split()) g = [[] for i in range(n)] for _ in range(q): a, b, c = map(int, input().split()) a -= 1 b -= 1 g[a].append([b, c]) g[b].append([a, c]) ans = 1 colors = [-1] * n for sv in range(n): if colors[sv] != -1: continue ans = ans * 2 % MOD colors[sv] = 0 deq = deque() deq.append(sv) while len(deq) > 0: v = deq.popleft() for nv, d in g[v]: new_color = colors[v] ^ d if colors[nv] == -1: colors[nv] = new_color deq.append(nv) elif colors[nv] != new_color: ans *= 0 print(ans)