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