/* -*- coding: utf-8 -*- * * 1421.cc: No.1421 国勢調査 (Hard) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 50; const int MAX_M = 10000; /* typedef */ typedef long long ll; /* global variables */ ll bs[MAX_M]; int ys[MAX_M]; /* subroutines */ bool elimination(int n, int m) { // n <= m for (int i = 0; i < n; i++) { ll bi = 1LL << i; if ((bs[i] & bi) == 0) { int j = i + 1; for (; j < m && (bs[j] & bi) == 0; j++); if (j < m) swap(bs[i], bs[j]), swap(ys[i], ys[j]); } if ((bs[i] & bi) == 0) continue; for (int j = i + 1; j < m; j++) if ((bs[j] & bi) != 0) bs[j] ^= bs[i], ys[j] ^= ys[i]; } for (int i = n - 1; i >= 0; i--) { ll bi = 1LL << i; if ((bs[i] & bi) == 0 && ys[i] != 0) return false; for (int j = i - 1; j >= 0; j--) if ((bs[j] & bi) != 0) bs[j] ^= bi, ys[j] ^= ys[i]; } for (int j = 0; j < m; j++) if (bs[j] == 0 && ys[j] != 0) return false; return true; } /* main */ int main() { int n, m; scanf("%d%d", &n, &m); ll nbits = 1LL << n; for (int i = 0; i < m; i++) { int ai; scanf("%d", &ai); for (int j = 0; j < ai; j++) { int bj; scanf("%d", &bj); bj--; bs[i] |= (1LL << bj); } scanf("%d", ys + i); } bool f = elimination(min(n, m), m); if (f) for (int i = 0; i < n; i++) printf("%d\n", ys[i]); else puts("-1"); return 0; }