using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, q) = (c[0], c[1]); var map = NArr(q); var tree = new List<(int to, int val)>[n]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List<(int to, int val)>(); foreach (var edge in map) { tree[edge[0] - 1].Add((edge[1] - 1, edge[2])); tree[edge[1] - 1].Add((edge[0] - 1, edge[2])); } var ans = 1L; var mod = 998_244_353; var len = Enumerable.Repeat(-1, n).ToArray(); for (var i = 0; i < n; ++i) { if (len[i] < 0) { len[i] = 0; ans = ans * 2 % mod; if (!DFS(i, tree, len)) { WriteLine(0); return; } } } WriteLine(ans); } static bool DFS(int cur, List<(int to, int val)>[] tree, int[] len) { foreach (var next in tree[cur]) { if (len[next.to] < 0) { len[next.to] = len[cur] ^ next.val; if (!DFS(next.to, tree, len)) return false; } else { if (len[next.to] != (len[cur] ^ next.val)) return false; } } return true; } }