#include #include #include struct ReduceMap{ std::vector> vec; ReduceMap(std::size_t n): vec(n) {} bool insert(uint64_t key, uint32_t value){ if(key == 0){ return value == 0; }else{ int index = __builtin_ctzll(key); if(vec[index].first == 0){ vec[index].first = key; vec[index].second = value; return true; }else{ return insert(key ^ vec[index].first, value ^ vec[index].second); } } } std::vector construct() const { std::size_t n = vec.size(); std::vector ret(n, 0); for(std::size_t i = n - 1;; --i){ if(vec[i].first){ uint32_t x = vec[i].second; for(std::size_t j = i + 1; j < n; ++j){ if(vec[i].first >> j & 1){ x ^= ret[j]; } } ret[i] = x; } if(i == 0){ return std::move(ret); } } } }; int main(){ std::size_t n, m; std::cin >> n >> m; assert(1 <= n && n <= 50); assert(1 <= m && m <= 100000); ReduceMap map(n); for(std::size_t i = 0; i < m; ++i){ std::size_t a; std::cin >> a; uint64_t visited = 0; for(std::size_t j = 0; j < a; ++j){ int b; std::cin >> b; --b; visited |= 1ull << b; } uint32_t y; std::cin >> y; if(!map.insert(visited, y)){ std::cout << "-1" << std::endl; return 0; } } auto ans = map.construct(); for(uint32_t i : ans){ std::cout << i << std::endl; } }