#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; using Graph=vector>; vector color; bool dfs(const Graph &G,int v,int cur=0){ color[v]=cur; for(auto next_v:G[v]){ if(color[next_v]!=-1){ if(color[next_v]==cur) return false; continue; } if(!dfs(G,next_v,1-cur)) return false; } return true; } class Dis{ public: vector rank,p,siz; Dis(int s){ rank.resize(s,0); p.resize(s,0); siz.resize(s,1); rep(i,s) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(same(x,y)) return; link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; siz[x]+=siz[y]; } else{ p[x]=y; siz[y]+=siz[x]; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x != p[x]) p[x]=findSet(p[x]); return p[x]; } int size(int x){ return siz[findSet(x)]; } }; const int MOD=998244353; ll modpow(ll x,ll n){ x%=MOD; ll ans=1; while(n){ if(n&1) ans=ans*x%MOD; x=x*x%MOD; n/=2; } return ans; } int main(){ int n,q; cin>>n>>q; Dis ds=Dis(n),ds1=Dis(n); Graph G(n); vector A(q),B(q),C(q); rep(i,q){ int a,b,c; cin>>a>>b>>c; a--,b--; A[i]=a,B[i]=b,C[i]=c; } rep(i,q){ if(C[i]==1) continue; ds.unite(A[i],B[i]); } rep(i,q){ if(C[i]==0) continue; if(ds.same(A[i],B[i])){ cout<<0<