#include #include #include #include #include #include #include #include #include using namespace std; long long N, M; long long A[1 << 18], Y[1 << 18]; long long Answer[1 << 18]; bool flag = false; long long solve(vector> A) { // 掃き出し法 sort(A.begin(), A.end()); for (int i = 49; i >= 0; i--) { for (int j = 0; j < A.size(); j++) { if ((A[j].first & (1LL << i)) != 0) { for (int k = j + 1; k < A.size(); k++) { if ((A[k].first & (1LL << i)) == 0) continue; A[k].first ^= A[j].first; A[k].second ^= A[j].second; } break; } } sort(A.begin(), A.end()); } if (A[0].first == 0 && A[0].second == 1) return -1; for (int i = 0; i < (int)A.size() - 1; i++) { if (A[i].first == A[i + 1].first && A[i].second != A[i + 1].second) return -1; } // ビットの計算 long long bit[55]; for (int i = 0; i < 55; i++) bit[i] = 0; for (int i = 0; i < (int)A.size(); i++) { int maximum = 0, s = A[i].second; for (int j = 0; j < 55; j++) { if ((A[i].first & (1LL << j)) != 0LL) maximum = j; } for (int j = 0; j < maximum; j++) { if ((A[i].first & (1LL << j)) != 0LL) s ^= bit[j]; } bit[maximum] = s; } long long ret = 0; for (int i = 0; i < 55; i++) { if (bit[i] == 1) ret += (1LL << i); } return ret; } int main() { // Step 1. 入力 cin >> N >> M; for (int i = 1; i <= M; i++) { long long s, t; cin >> s; for (int j = 0; j < s; j++) { cin >> t; A[i] += (1LL << (t - 1)); } cin >> Y[i]; } // Step #2. ビットごとに計算 for (int i = 0; i < 30; i++) { vector> vec; for (int j = 1; j <= M; j++) { vec.push_back(make_pair(A[j], (Y[j] / (1LL << i)) % 2LL)); } long long Z = solve(vec); if (Z == -1) flag = true; for (int j = 0; j < N; j++) Answer[j] += (1LL << i) * ((Z / (1LL << j)) % 2LL); } // Step #3. 出力 if (flag == true) { cout << "-1" << endl; } else { for (int i = 0; i < N; i++) cout << Answer[i] << endl; } return 0; }