#include using namespace std; vector vst; vector bt; void dfs(vector>> &E, int from){ vst[from] = 1; int alt; for(auto [to, C] : E[from]){ if (C == 1) alt = 1-bt[from]; else alt=bt[from]; if (vst[to]){ if (alt != bt[to]){ cout << -1 << endl; exit(0); } continue; } bt[to] = alt; dfs(E, to); } } int main(){ int N, M, A, B, Y; cin >> N >> M; vector ans(N); vector>>> E(30, vector>>(N)); for (int i=0; i> A >> B >> Y; A--; B--; for (int j=0; j<30; j++){ if (Y & 1<