#include using namespace std; #include using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) int main(){ int n,m;cin>>n>>m; vc v(n,vc(0)); rep(i,m){ int a,b,c;cin>>a>>b>>c; a--;b--; v[a].pb({b,c}); v[b].pb({a,c}); } vcx(n,0),bo(n,0); bool ans=true; auto f=[&](auto f,int a)->void{ bo[a]=1; for(auto [au,c]:v[a]){ int nc=x[a]^c; if(bo[au]&&nc!=x[au])ans=false; if(!bo[au]){ x[au]=nc; f(f,au); } } return; }; rep(i,n)if(!bo[i])f(f,i); if(ans)rep(i,n)cout<