#include using namespace std; const int mod=998244353; int rt[200000]; int getroot(int n){ if(rt[n]==-1)return n; else return rt[n]=getroot(rt[n]); } void unite(int a,int b){ a=getroot(a),b=getroot(b); if(a!=b){ rt[a]=b; } } long long modpow(long long a,int n){ long long ret=1,t=a; for(int i=0;i<30;i++){ if(n>>i&1)ret=ret*t%mod; t=t*t%mod; } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); fill(rt,rt+200000,-1); int N,Q; cin>>N>>Q; while(Q--){ int A,B,C; cin>>A>>B>>C; --A,--B; if(C==0){ unite(A,B); unite(A+N,B+N); }else{ unite(A,B+N); unite(A+N,B); } } for(int i=0;it; for(int i=0;i