#include using namespace std; typedef long long int ll; typedef pair P; typedef vector VI; typedef vector VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template bool chmax(T& x, const T& y){return (x bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;}; constexpr ll MOD=998244353; constexpr ll INF=2e18; int main(){ int n, q; cin >> n >> q; vector> g(n); int a, b, c; REP(i,q){ cin >> a >> b >> c; a--, b--; g[b].push_back({a,c}); g[a].push_back({b,c}); } VI f(n,-1); bool no=0; function dfs=[&](int v){ for(auto p:g[v]){ int to=p.first, flag=p.second; if(f[to]==-1){ f[to]=(f[v]==flag?0:1); dfs(to); } else if(f[to]!=(f[v]==flag?0:1)) no=1; } }; ll ans=1; REP(i,n){ if(f[i]==-1){ ans=ans*2%MOD; f[i]=0; dfs(i); } } if(no) ans=0; cout << ans << endl; return 0; }