#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; bool rcmp(int a, int b) { return a>b; } typedef long long LL; class mypcmp { public: bool operator()(const int& a, const int& b) { return agx[b]) { gg[b]=a; } else gg[a]=b; } set nei[100004]; char mk[100004]; int que[100004]; int as[100004], bs[100004], cs[100004]; #define MOD 998244353 int main() { int n, i, q, a, b, c, j; int h, t; LL r; scanf("%d %d", &n, &q); for (i=1; i<=n; i++) { gg[i]=i; gx[i]=0; } for (i=1; i<=q; i++) { scanf("%d %d %d", &a, &b, &c); as[i]=a; bs[i]=b; cs[i]=c; if (c==0) { a=findg(a); b=findg(b); if (a!=b) join(a,b); } } for (i=1; i<=q; i++) { a=as[i]; b=bs[i]; c=cs[i]; if (c==1) { a=findg(a); b=findg(b); nei[a].insert(b); nei[b].insert(a); } } r=1; for (i=1; i<=n; i++) mk[i]=0; for (i=1; i<=n; i++) { a=findg(i); if (mk[a]) continue; r*=2; r%=MOD; h=t=0; mk[a]=1; que[h++]=a; while(t