#line 1 "main.cpp" #include #include #include #include #include using namespace std; using lint = long long; void solve() { int n, m; cin >> n >> m; vector mat(m, 0); vector ys(m, 0); for (int i = 0; i < m; ++i) { int k; cin >> k; while (k--) { int x; cin >> x; mat[i] |= (1LL << (--x)); } cin >> ys[i]; } auto pmat = mat; auto pys = ys; vector chosen(m, false); for (int i = 0; i < n; ++i) { int p = -1; for (int j = 0; j < m; ++j) { if (chosen[j]) continue; if ((mat[j] >> i) & 1) p = j; } if (p == -1) continue; chosen[p] = true; for (int j = 0; j < m; ++j) { if (j == p) continue; if ((mat[j] >> i) & 1) { mat[j] ^= mat[p]; ys[j] ^= ys[p]; } } } fill(chosen.begin(), chosen.end(), false); vector ans(n, 0); for (int i = 0; i < n; ++i) { int p = -1; for (int j = 0; j < m; ++j) { if (chosen[j]) continue; if ((mat[j] >> i) & 1) p = j; } if (p == -1) continue; chosen[p] = true; ans[i] = ys[p]; } // judge for (int j = 0; j < m; ++j) { int x = 0; for (int i = 0; i < n; ++i) { if ((pmat[j] >> i) & 1) x ^= ans[i]; } if (x != pys[j]) { cout << "-1\n"; return; } } for (auto x : ans) cout << x << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }