#include #include using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) using mint = atcoder::modint998244353; int main(){ int n,q; cin>>n>>q; vector>> g(n); rep(i,q){ int a,b,c; cin>>a>>b>>c; a--;b--; g.at(a).push_back({b,c}); g.at(b).push_back({a,c}); } vector ans(n,-1); int ct=0; rep(i,n){ if(ans.at(i)!=-1) continue; ct++; ans.at(i)=0; queue q; q.push(i); while(!q.empty()){ int v=q.front(); q.pop(); for(auto [u,c]:g.at(v)){ if(ans.at(u)!=-1){ if(ans.at(u)!=(ans.at(v)^c)){ cout<<0<