AtCoder Beginner Contest 128 - Switches

We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.
Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2.
How many combinations of "on" and "off" states of the switches light all the bulbs?

-----Constraints-----
 - 1 \leq N, M \leq 10
 - 1 \leq k_i \leq N
 - 1 \leq s_{ij} \leq N
 - s_{ia} \neq s_{ib} (a \neq b)
 - p_i is 0 or 1.
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M
k_1 s_{11} s_{12} ... s_{1k_1}
:
k_M s_{M1} s_{M2} ... s_{Mk_M}
p_1 p_2 ... p_M

-----Output-----
Print the number of combinations of "on" and "off" states of the switches that light all the bulbs.

-----Sample Input-----
2 2
2 1 2
1 2
0 1

-----Sample Output-----
1

 - Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2.
 - Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2.
There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 1.

Difficulty: EASY

Starter code:

Solutions:
(N, M) = map(int, input().split())
ks = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
temp = [0] * M
ans = 0
for i in range(2 ** N):
	temp = [0] * M
	for h in range(N):
		if i >> h & 1:
			for g in range(M):
				if h + 1 in ks[g]:
					temp[g] += 1
	for k in range(M):
		temp[k] = temp[k] % 2
	if temp == P:
		ans += 1
print(ans)


(n, m) = map(int, input().split(' '))
ks = [list(map(int, input().split(' '))) for i in range(m)]
p = list(map(int, input().split(' ')))
total = 0
for i in range(2 ** n):
	count = 0
	den = [0 for i in range(m + 1)]
	for j in range(n):
		if i >> j & 1:
			for k in range(m):
				if j + 1 in ks[k][1:]:
					den[k + 1] += 1
	for j in range(m):
		if den[j + 1] % 2 == p[j]:
			count += 1
	if count == m:
		total += 1
print(total)


(N, M) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
for i in range(M):
	del X[i][0]
count = 0
for i in range(2 ** N):
	check = True
	for j in range(M):
		on = 0
		for k in X[j]:
			if i >> k - 1 & 1 == 1:
				on += 1
		if on % 2 != p[j]:
			check = False
	if check:
		count += 1
print(count)


(n, m) = map(int, input().split())
k = [0] * m
s = [0] * m
for i in range(m):
	tmp = list(map(int, input().split()))
	k[i] = tmp[0]
	s[i] = tmp[1:]
p = list(map(int, input().split()))
res = 0
for bit in range(2 ** n):
	for i in range(m):
		cnt = 0
		for sw in s[i]:
			if bit >> sw - 1 & 1:
				cnt += 1
		if cnt % 2 != p[i]:
			break
	else:
		res += 1
print(res)


(n, m) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for b in range(2 ** n):
	onswitch = [i + 1 for i in range(n) if b >> i & 1]
	if all((sum((o in s for o in onswitch)) % 2 == p for (s, p) in zip(S, P))):
		ans += 1
print(ans)


(n, m) = map(int, input().split())
swl = [list(map(int, input().split())) for _ in range(m)]
pl = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	sw = [0] * n
	light_cnt = 0
	for j in range(n):
		if i >> j & 1:
			sw[j] += 1
	for j in range(m):
		wl = swl[j][1:]
		sw_cnt = 0
		for wi in wl:
			if sw[wi - 1] == 1:
				sw_cnt += 1
		if sw_cnt % 2 == pl[j]:
			light_cnt += 1
	if light_cnt == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = []
for i in range(m):
	ks = list(map(int, input().split()))
	s.append(ks[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	for j in range(m):
		cnt = 0
		for k in s[j]:
			if i & 1 << k - 1:
				cnt += 1
		if cnt % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
result = 0
for i in range(2 ** n):
	flag = 1
	for j in range(m):
		count = 0
		for k in range(s[j][0]):
			if i >> s[j][k + 1] - 1 & 1 == 1:
				count += 1
		if count % 2 != p[j]:
			flag = 0
	if flag == 1:
		result += 1
print(result)


(n, m) = map(int, input().split())
L = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	on = bin(i)[2:].zfill(n)
	for (s, p) in zip(L, P):
		if sum((int(on[sij - 1]) for sij in s)) % 2 != p:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
b = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	c = []
	q = True
	for j in range(n):
		c.append(i >> j & 1)
	for k in range(m):
		p = 0
		for l in range(1, a[k][0] + 1):
			if c[a[k][l] - 1] == 1:
				p += 1
		if p % 2 != b[k]:
			q = False
	if q:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
S = []
for _ in range(m):
	s = list(map(int, input().split()))
	S.append(s[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	for k in range(m):
		sw = 0
		for j in range(n):
			if i >> j & 1 and j + 1 in S[k]:
				sw += 1
		if sw % 2 != p[k]:
			break
	else:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
Ss = [list(map(int, input().split()[1:])) for _ in range(M)]
p = list(map(int, input().split()))
cnt = 0
for L in range(pow(2, N)):
	for (pi, s) in zip(p, Ss):
		x = pi
		for si in s:
			x ^= (L & 1 << si - 1 != 0) * 1
		if x != 0:
			break
	else:
		cnt += 1
print(cnt)


from itertools import product
(N, M) = list(map(int, input().split()))
bulbs = [list([int(x) - 1 for x in input().split()]) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for x in product([0, 1], repeat=N):
	is_on = [0] * M
	for i in range(M):
		(k, *switches) = bulbs[i]
		cnt = sum((x[s] for s in switches))
		if cnt % 2 == P[i]:
			is_on[i] = 1
	if all(is_on):
		ans += 1
print(ans)


3
import sys
input = lambda : sys.stdin.readline().strip()
(n, m) = [int(x) for x in input().split()]
s = [[int(x) - 1 for x in input().split()][1:] for i in range(m)]
p = [int(x) for x in input().split()]
print(sum((1 for mask in range(1 << n) if all((sum((mask >> bulb & 1 for bulb in s[i])) % 2 == p[i] for i in range(m))))))


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for num in range(1 << n):
	all = True
	for M in range(m):
		swt = 0
		for k in s[M][1:]:
			if num & 1 << k - 1:
				swt += 1
		if swt % 2 != p[M]:
			all = False
			break
	if all:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for bits in range(2 ** n):
	ok = True
	for (i, k) in enumerate(K):
		ok = ok and sum((bits >> s - 1 & 1 for s in k[1:])) % 2 == P[i]
	if ok:
		ans += 1
print(ans)


import itertools
(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
sss = 0
for c in itertools.product([0, 1], repeat=n):
	ans = 0
	for i in range(m):
		cnt = 0
		for j in range(l[i][0]):
			if c[l[i][j + 1] - 1] == 1:
				cnt += 1
		if cnt % 2 == p[i]:
			ans += 1
	if ans == m:
		sss += 1
print(sss)


(N, M) = map(int, input().split())
S = [tuple(map(int, input().split()))[1:] for _ in range(M)]
P = tuple(map(int, input().split()))
ans = 0
for state in range(2 ** N):
	for m in range(M):
		count = 0
		for s in S[m]:
			if state & 1 << s - 1:
				count += 1
		if count % 2 != P[m]:
			break
	else:
		ans += 1
print(ans)


def abc128_c():
	(N, M) = list(map(int, input().split()))
	connected_switches = []
	for i in range(M):
		tmp = list(map(int, input().split()))[1:]
		connected_switches.append(tmp)
	p = list(map(int, input().split()))
	ans = 0
	for i in range(2 ** N):
		for j in range(M):
			on_switch_count = 0
			for k in range(N):
				if k + 1 in connected_switches[j] and i >> k & 1:
					on_switch_count += 1
			if on_switch_count % 2 != p[j]:
				break
			if j == M - 1:
				ans += 1
	print(ans)

def __starting_point():
	abc128_c()
__starting_point()


(n, m) = map(int, input().split())
sw = []
for _ in range(m):
	(k, *s) = map(int, input().split())
	sw.append(s)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	L = [i >> j & 1 for j in range(n)]
	if all([sum([L[s - 1] for s in sw[k]]) % 2 == p[k] for k in range(m)]):
		ans += 1
print(ans)


((n, m), *s, p) = [list(map(int, t.split())) for t in open(0)]
a = 0
r = range
for i in r(1 << n):
	c = [0] * m
	for j in r(n):
		for k in r(m):
			c[k] += i >> j & (j + 1 in s[k][1:])
	a += all((j == i % 2 for (i, j) in zip(c, p)))
print(a)


import copy

def dfs(i, lst):
	nonlocal ans
	if i == n:
		ans.append(lst)
		return
	tmp1 = copy.copy(lst)
	tmp1.append(0)
	dfs(i + 1, tmp1)
	tmp2 = copy.copy(lst)
	tmp2.append(1)
	dfs(i + 1, tmp2)
(n, m) = map(int, input().split())
ans = []
tmp = [0]
dfs(0, tmp)
s = []
k = []
for i in range(m):
	tmp = list(map(int, input().split()))
	k.append(tmp[0])
	s.append(tmp[1:])
p = list(map(int, input().split()))
cnt = 0
for i in range(len(ans)):
	cnt_i = 0
	for mi in range(m):
		sum_s = 0
		for ki in range(len(s[mi])):
			sum_s += ans[i][s[mi][ki]]
		if sum_s % 2 == p[mi]:
			cnt_i += 1
	if cnt_i == m:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
res = 0
for i in range(2 ** n):
	t = bin(i + 2 ** n)[3:]
	judge = True
	for j in range(m):
		l = 0
		for k in ks[j][1:]:
			if t[k - 1] == '1':
				l += 1
		if l % 2 == p[j]:
			continue
		else:
			judge = False
			break
	if judge:
		res += 1
print(res)


(N, M) = map(int, input().split())
A = [[0 for _ in range(N)] for _ in range(M)]
for i in range(M):
	S = list(map(int, input().split()))
	for j in S[1:]:
		A[i][j - 1] = 1
P = list(map(int, input().split()))
ans = 0
for bit in range(2 ** N):
	b = bin(bit)[2:].zfill(N)
	X = [0] * M
	for i in range(M):
		for j in range(N):
			if A[i][j] == 1 and b[j] == '1':
				X[i] = (X[i] + 1) % 2
	tmp = 0
	for i in range(M):
		if P[i] == X[i]:
			tmp += 1
	if tmp == M:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
k = [0] * m
s = [[] for _ in range(m)]
for i in range(m):
	(k[i], *s[i]) = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	res = 0
	for a in range(m):
		tmp = p[a] ^ 1
		for j in s[a]:
			if i >> j - 1 & 1:
				tmp ^= 1
		res += tmp
	if res == m:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = []
for i in range(M):
	(k, *s) = list(map(int, input().split()))
	S.append(s)
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	if all([sum([i & 2 ** (n - 1) > 0 for n in S[m]]) % 2 == P[m] for m in range(M)]):
		ans += 1
print(ans)


def II():
	return int(input())

def MII():
	return list(map(int, input().split()))

def LII():
	return list(map(int, input().split()))

def main():
	(N, M) = MII()
	s = []
	for _ in range(M):
		s.append(list(map(int, input().split()))[1:])
	p = LII()
	ans = 0
	for i in range(2 ** N, 2 ** (N + 1)):
		b = bin(i)[3:]
		t = [0] * M
		for (j, sj) in enumerate(s):
			for (k, bi) in enumerate(list(b)):
				if bi == '1' and k + 1 in sj:
					t[j] += 1
			if t[j] % 2 != p[j]:
				ans -= 1
				break
		ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, m) = list(map(int, input().split()))
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	light = 0
	for (ki, j) in enumerate(k):
		switch = 0
		for s in j[1:]:
			if i >> s - 1 & 1:
				switch += 1
		if switch % 2 == p[ki]:
			light += 1
	if light == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
c = 0
for _ in range(2 ** n):
	s = str(bin(_))[2:].zfill(n)
	f = 1
	for i in range(m):
		a = 0
		for j in range(1, k[i][0] + 1):
			a += int(s[k[i][j] - 1])
		if a % 2 != p[i]:
			f = 0
			break
	if f:
		c += 1
print(c)


(N, M) = map(int, input().split())
A = [0] * M
for i in range(M):
	A[i] = list(map(int, input().split()))
P = list(map(int, input().split()))
F = 0
for i in range(2 ** N):
	E = 0
	Sui = [0] * N
	for j in range(N):
		if i >> j & 1:
			Sui[j] += 1
	for k in range(M):
		D = 0
		for l in range(1, A[k][0] + 1):
			if Sui[A[k][l] - 1] == 1:
				D += 1
		if D % 2 == P[k]:
			E += 1
	if E == M:
		F += 1
print(F)


(N, M) = map(int, input().split())
S_lists = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
count = 0
for n in range(2 ** N):
	l = 1
	for (p, S) in zip(P, S_lists):
		l *= sum([int(bin(n)[2:].zfill(N)[s - 1]) for s in S]) % 2 == p
	count += l
print(count)


(N, M) = list(map(int, input().split()))
K = {i: [] for i in range(M)}
for i in range(M):
	t = list(map(int, input().split()))
	for j in range(1, len(t)):
		K[i].append(t[j] - 1)
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	switch = [False] * N
	for j in range(N):
		if i >> j & 1:
			switch[j] = True
	isok = True
	for m in range(M):
		t = 0
		for k in K[m]:
			if switch[k]:
				t += 1
		if t % 2 != P[m]:
			isok = False
	if isok:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = [[int(i) - 1 for i in input().split()] for _ in range(M)]
P = [int(i) for i in input().split()]
ans = 0
for i in range(1 << N):
	for j in range(M):
		cnt = 0
		for s in S[j][1:]:
			if i >> s & 1:
				cnt += 1
		if cnt % 2 != P[j]:
			break
	else:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = []
for i in range(M):
	ks = list(map(int, input().split()))
	S.append(sum((1 << s - 1 for s in ks[1:])))
p = list(map(int, input().split()))
ans = 0
for state in range(2 ** N):
	on = True
	for m in range(M):
		on = bin(S[m] & state).count('1') % 2 == p[m]
		if not on:
			break
	ans += on
print(ans)


(N, M) = map(int, input().split())
S = [tuple(map(int, input().split()[1:])) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for b in range(1 << N):
	for (i, s) in enumerate(S):
		c = 0
		for t in s:
			if b & 1 << t - 1:
				c += 1
		if c % 2 != P[i]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
a = 0
for bit in range(1 << n):
	for j in range(m):
		c = 0
		for k in s[j][1:]:
			if bit & 1 << k - 1:
				c += 1
		if c % 2 != p[j]:
			break
	else:
		a += 1
print(a)


(n, m) = map(int, input().split())
s = eval('list(map(int,input().split()[1:])),' * m)
(*p,) = map(int, input().split())
a = 0
r = range
for i in r(1 << n):
	c = [0] * m
	for j in r(n):
		for k in r(m):
			c[k] += i >> j & 1 and j + 1 in s[k]
	a += all((j == i % 2 for (i, j) in zip(c, p)))
print(a)


(N, M) = map(int, input().split())
mat = [[int(i) for i in input().split()] for k in range(M)]
p = [int(i) for i in input().split()]
switch = [0] * N
O = [0] * M
L = [False] * M
ans = 0
for i in range(2 ** N):
	switchsub = list(format(i, 'b'))
	for j in range(len(switchsub)):
		switch[-j - 1] = switchsub[-j - 1]
	for j in range(N):
		if switch[j] == '1':
			for k in range(M):
				for l in range(1, len(mat[k])):
					if mat[k][l] == j + 1:
						O[k] += 1
	for j in range(M):
		if O[j] % 2 == p[j]:
			L[j] = True
	if False not in L:
		ans += 1
		switch = [0] * N
		O = [0] * M
		L = [False] * M
	if False in L:
		switch = [0] * N
		O = [0] * M
		L = [False] * M
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
(*p,) = map(int, input().split())
print(sum([all([sum([i >> k - 1 for k in s[j]]) % 2 == p[j] for j in range(m)]) for i in range(2 ** n)]))


(n, m) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
cnt = 0
for i in range(2 ** n):
	Q = 0
	switch = set([i + 1 for (i, j) in enumerate(format(i, 'b').zfill(n)[::-1]) if j == '1'])
	for (k, j) in enumerate(S):
		if len(switch & set(j)) % 2 == P[k]:
			Q += 1
	if Q == m:
		cnt += 1
print(cnt)


from itertools import product
(n, m) = map(int, input().split())
k = []
s = []
for _ in range(m):
	(a, *b) = map(int, input().split())
	k.append(a)
	s.append(b)
p = list(map(int, input().split()))
print(sum((all((sum((i[b - 1] for b in a)) % 2 == x for (a, x) in zip(s, p))) for i in product((0, 1), repeat=n))))


def inpl():
	return list(map(int, input().split()))
(N, M) = inpl()
L = [0] * M
for i in range(M):
	for s in inpl()[1:]:
		L[i] += pow(2, s - 1)
P = inpl()
print(sum([sum([bin(L[j] & i).count('1') % 2 == P[j] for j in range(M)]) == M for i in range(pow(2, N))]))


(n, m) = map(int, input().split())
s_lis = []
for i in range(2 ** n):
	lis = []
	for j in range(len(bin(2 ** n)) - 3):
		if i >> j & 1:
			lis.append(1)
		else:
			lis.append(0)
	s_lis.append(lis)
b_lis = []
for k in range(m):
	b_lis.append(list(map(int, input().split())))
light = list(map(int, input().split()))
cnt = 0
for s in s_lis:
	c_lis = []
	for b in b_lis:
		c = 0
		for x in range(b[0]):
			c += s[b[x + 1] - 1]
		c_lis.append(c)
	c_lis = list(map(lambda y: y % 2, c_lis))
	if c_lis == light:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for m in range(m)]
p = list(map(int, input().split()))
cnt = 0
for i in range(1 << n):
	for j in range(m):
		switch = 0
		for k in range(n):
			if i >> k & 1 and k + 1 in s[j]:
				switch += 1
		if switch % 2 != p[j]:
			break
	else:
		cnt += 1
print(cnt)


(N, M) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(M)]
(*p,) = map(int, input().split())
t = 0
a = 0
for i in range(2 ** N):
	t = 0
	for j in range(M):
		if sum((1 for h in k[j][1:] if i >> h - 1 & 1)) % 2 == p[j]:
			t += 1
	if t == M:
		a += 1
print(a)


import itertools
(N, M) = map(int, input().split())
k = []
for _ in range(M):
	k.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for (i, s) in enumerate(itertools.product([0, 1], repeat=N)):
	if all([sum([s[j - 1] for j in v]) % 2 == t for (v, t) in zip(k, p)]):
		ans += 1
print(ans)


(N, M) = map(int, input().split())
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	lit = [0] * M
	for (j, switches) in enumerate(L):
		cnt = 0
		for s in switches:
			if i >> s - 1 & 1:
				cnt += 1
		if cnt % 2 == P[j]:
			lit[j] = 1
	if all(lit):
		ans += 1
print(ans)


import itertools
(N, M) = map(int, input().split())
KS = []
for _ in range(M):
	KS.append(tuple(map(int, input().split())))
P = tuple(map(int, input().split()))
ans = 0
for t in itertools.product([0, 1], repeat=N):
	for m in range(M):
		if sum((t[x - 1] for x in KS[m][1:])) % 2 != P[m]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
k = []
for _ in range(m):
	k.append(list(map(int, input().split()))[1:])
(*p,) = map(int, input().split())
count = 0
for i in range(2 ** n):
	res = 0
	for (kc, pc) in zip(k, p):
		s = sum([i >> j - 1 & 1 for j in kc]) % 2
		res += s == pc
	count += res == len(p)
print(count)


(N, M) = [int(s) for s in input().split()]
S = []
for _ in range(M):
	l = [int(s) for s in input().split()]
	S.append(l[1:])
P = [int(s) for s in input().split()]
result = 0
for i in range(2 ** N):
	if all((sum(['{:0{N}b}'.format(i, N=N)[t - 1] == '1' for t in s]) % 2 == P[j] for (j, s) in enumerate(S))):
		result += 1
print(result)


f = lambda : map(int, input().split())
(n, m) = f()
S = [[0] * n for _ in [0] * m]
for i in range(m):
	(_, *s) = f()
	for j in s:
		S[i][j - 1] = 1
p = [*f()]
print(sum((all((sum((i >> j & 1 * S[k][j] for j in range(n))) % 2 == p[k] for k in range(m))) for i in range(2 ** n))))


(N, M) = map(int, input().split())
switch = []
for _ in range(M):
	tmp = list(map(int, input().split()))
	switch.append(tmp[1:])
p = list(map(int, input().split()))
from itertools import product
candidate = list(product([0, 1], repeat=N))
ans = 0
for cand in candidate:
	flag = True
	for (idx, snum) in enumerate(switch):
		tmp = 0
		for s in snum:
			tmp += cand[s - 1]
		if p[idx] != tmp % 2:
			flag = False
			break
	if flag:
		ans += 1
print(ans)


def LI():
	return list(map(int, input().split()))
(N, M) = LI()
ks = [LI() for _ in range(M)]
p = LI()
ans = 0
for i in range(2 ** N):
	bit = [i >> j & 1 for j in range(N)]
	for (j, x) in enumerate(ks):
		if p[j] != sum([bit[y - 1] for y in x[1:]]) % 2:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [[]] * m
for i in range(m):
	s[i] = list(map(int, input().split()))
	del s[i][0]
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
	x = 0
	for i in range(m):
		y = 0
		for j in s[i]:
			if bit & 1 << j - 1:
				y += 1
		if y % 2 == p[i] % 2:
			x += 1
	if x == m:
		ans += 1
print(ans)


from itertools import product, repeat
import numpy as np
input_row = lambda : [int(_) for _ in input().split(' ')]
(N, M) = input_row()
C = np.zeros((M, N), dtype=np.int32)
for i in range(M):
	s = input_row()[1:]
	for s_ in s:
		C[i, s_ - 1] = 1
p = input_row()
all_on_num = 0
for S_ in product(*repeat([1, 0], N)):
	S = np.array(S_)
	L = C.dot(S) % 2 == p
	L_on = L[L == True]
	all_on = len(L_on) == M
	if all_on:
		all_on_num += 1
print(all_on_num)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	t = ['off'] * n
	x = i
	j = 0
	while x > 0:
		if x % 2 != 0:
			t[j] = 'on'
		x = x // 2
		j += 1
	flg = True
	for j in range(m):
		z = 0
		for k in range(1, s[j][0] + 1):
			if t[s[j][k] - 1] == 'on':
				z += 1
		if z % 2 != p[j]:
			flg = False
			break
	if flg:
		ans += 1
print(ans)


I = lambda : map(int, input().split())
(N, M) = I()
sw = []
for _ in [0] * M:
	(_, *s) = I()
	sw += [s]
(*p,) = I()
r = 0
for i in range(2 ** N):
	k = str(bin(i))[2:].rjust(N, '0')
	f = True
	for j in range(M):
		t = 0
		for s in sw[j]:
			if k[s - 1] == '1':
				t += 1
		if t % 2 != p[j]:
			f = False
			break
	if f:
		r += 1
print(r)


(n, m) = map(int, input().split())
ans = 0
e = [set(list(map(int, input().split()))[1:]) for i in range(m)]
f = list(map(int, input().split()))
for i in range(2 ** n):
	l = {a for (a, b) in zip(range(1, n + 1), bin(i)[2:].zfill(n)) if b == '1'}
	for j in range(1, m + 1):
		if len(e[j - 1] & l) % 2 != f[j - 1]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [None] * m
for i in range(m):
	(k, *s[i]) = map(lambda x: int(x) - 1, input().split())
p = list(map(int, input().split()))
ans = 0
for b in range(1 << n):
	f = True
	for i in range(m):
		cnt = sum((b >> x & 1 for x in s[i]))
		f &= cnt % 2 == p[i]
	ans += f
print(ans)


(N, M) = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for j in range(M):
		t = 0
		for k in range(1, ks[j][0] + 1):
			if i >> ks[j][k] - 1 & 1:
				t += 1
		if t % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


3
(N, M) = (int(x) for x in input().split())
S = []
for i in range(M):
	S.append([int(x) - 1 for x in input().split()][1:])
P = [int(x) for x in input().split()]
ret = 0
for bit in range(2 ** N):
	on = [i for i in range(N) if bit & 1 << i]
	if all((sum((1 for switch in S[i] if switch in on)) % 2 == P[i] for i in range(M))):
		ret += 1
print(ret)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for _ in range(2 ** n):
	pattern = list(map(int, list(bin(_)[2:].zfill(n))))
	if all((sum((pattern[sw2 - 1] for sw2 in ss)) % 2 == pp for (ss, pp) in zip(s, p))):
		count += 1
print(count)


(N, M) = map(int, input().split())
k = []
s = []
for i in range(M):
	ks = list(map(int, input().split()))
	k.append(ks[0])
	s.append(list(map(lambda x: x - 1, ks[1:])))
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	isOK = True
	for j in range(M):
		sum = 0
		for x in s[j]:
			sum += i >> x & 1
		if sum % 2 != p[j]:
			isOK = False
	if isOK:
		ans += 1
print(ans)


import itertools
INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

def do():
	(n, m) = INTM()
	cnct = []
	for i in range(m):
		temp = LIST()
		temp = temp[1:]
		cnct.append(temp)
	ps = LIST()
	ans = 0
	for bit in range(2 ** n):
		check = [0] * m
		for i in range(n):
			if bit >> i & 1:
				for k in range(m):
					if i + 1 in cnct[k]:
						check[k] += 1
		flg = True
		for k in range(m):
			if check[k] % 2 != ps[k]:
				flg = False
		if flg:
			ans += 1
	print(ans)

def __starting_point():
	do()
__starting_point()


(n, m) = map(int, input().split())
s = [sum(list(map(lambda x: 2 ** (int(x) - 1), input().split()[1:]))) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	cnt = 0
	for j in range(m):
		if sum([((i & s[j]) >> k) % 2 for k in range(n)]) % 2 == p[j]:
			cnt += 1
	if cnt == m:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
s = []
for i in range(m):
	tmp = list(map(int, input().split()))[1:]
	s.append(sum((2 ** (i - 1) for i in tmp)))
p = list(map(int, input().split()))
c = 0
for i in range(2 ** n):
	for j in range(m):
		if bin(i & s[j]).count('1') % 2 != p[j]:
			break
	else:
		c += 1
print(c)


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
c = 0
for _ in range(2 ** n):
	s = format(_, '0{}b'.format(n))
	f = 1
	for i in range(m):
		a = 0
		for j in range(1, k[i][0] + 1):
			a += int(s[k[i][j] - 1])
		if a % 2 != p[i]:
			f = 0
			break
	if f:
		c += 1
print(c)


(n, m) = map(int, input().split())
s = []
for i in range(m):
	inp = list(map(lambda x: int(x) - 1, input().split()))
	s.append(inp[1:])
p = list(map(int, input().split()))
c = 0
for i in range(2 ** n):
	st = []
	for j in range(m):
		t = 0
		for k in s[j]:
			if i & 2 ** k:
				t ^= 1
		st.append(t)
	if p == st:
		c += 1
print(c)


import sys
input = sys.stdin.readline

def slove():
	(N, M) = map(int, input().split())
	light = []
	for i in range(M):
		connecting_sw = list(map(int, input().split()))
		light.append(connecting_sw[1:])
	on = list(map(int, input().split()))
	ans = 0
	for i in range(1 << N):
		light_on = [0] * M
		for j in range(N):
			if i >> j & 1:
				a = 0
				for item in light:
					if j + 1 in item:
						light_on[a] = (light_on[a] + 1) % 2
					a += 1
		a = 0
		for i in range(M):
			if on[i] == light_on[i]:
				a += 1
				continue
			break
		if a == M:
			ans += 1
	print(ans)

def __starting_point():
	slove()
__starting_point()


(n, m) = list(map(int, input().split()))
switch = []
kl = []
for i in range(m):
	temp = list(map(int, input().split()))
	kl.append(temp[0])
	switch.append(temp[1:])
pl = list(map(int, input().split()))
pattern = [[0 for _ in range(n)] for _1 in range(2 ** n)]
for i in range(2 ** n):
	for j in range(n):
		if i >> j & 1:
			pattern[i][j] = 1
ans = 0
for (ptnum, spt) in enumerate(pattern):
	islit = True
	for lightnum in range(m):
		count = 0
		for s in switch[lightnum]:
			if spt[s - 1] == 1:
				count += 1
		if count % 2 != pl[lightnum]:
			islit = False
			break
	if islit:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for (j, k) in enumerate(S):
		if sum((1 for kj in k if i >> kj - 1 & 1)) % 2 != P[j]:
			break
		if j == len(S) - 1:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
line = []
for i in range(m):
	(k, *s) = map(int, input().split())
	line.append(list(s))
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
	switch = [0] * (n + 1)
	tf = 1
	for i in range(n):
		if bit >> i & 1:
			switch[i + 1] = 1
	for i in range(m):
		cnt = 0
		for v in line[i]:
			if switch[v]:
				cnt += 1
		if cnt % 2 != p[i]:
			tf = 0
	if tf:
		ans += 1
print(ans)


import sys
(N, M) = list(map(int, input().split()))
k = []
s = []
for i in range(M):
	(_k, *_s) = list(map(int, input().split()))
	k.append(_k)
	s.append(_s)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	sw = [0 for _ in range(N)]
	for j in range(N):
		if i >> j & 1:
			sw[j] = 1
	for m in range(M):
		mod = 0
		for switch in s[m]:
			mod += sw[switch - 1]
		if mod % 2 != p[m]:
			break
	else:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
k = []
s = []
for i in range(M):
	a = list(map(int, input().split()))
	k.append(a[0])
	s.append(a[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	ri_count = 0
	for j in range(M):
		sw_count = 0
		for l in range(k[j]):
			if i >> s[j][l] - 1 & 1:
				sw_count += 1
		if sw_count % 2 == p[j]:
			ri_count += 1
	if ri_count == M:
		ans += 1
print(ans)


import itertools
inpl = lambda : list(map(int, input().split()))
(N, M) = inpl()
ks = []
for i in range(M):
	ks.append(inpl())
p = inpl()
ans = 0
for s in itertools.product(range(2), repeat=N):
	for i in range(M):
		if (sum([s[n - 1] for n in ks[i][1:]]) - p[i]) % 2:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	tmp = []
	for j in range(n):
		if i >> j & 1:
			tmp.append(j + 1)
	for k in range(m):
		if len(set(tmp) & set(s[k])) % 2 != p[k]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
l = [[int(x) for x in input().split()] for _ in range(m)]
p = [int(x) for x in input().split()]
t = 0
for i in range(2 ** n):
	f = True
	for j in range(m):
		c = 0
		for k in range(1, l[j][0] + 1):
			if i >> l[j][k] - 1 & 1:
				c += 1
		if c & 1 != p[j]:
			f = False
			break
	if f == True:
		t += 1
print(t)


(n, m) = map(int, input().split())
f = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** n):
	Bit = [0] * n
	for j in range(n):
		if i >> j & 1:
			Bit[j] = 1
	same = 0
	for k in range(m):
		sum = 0
		for l in range(f[k][0]):
			if Bit[f[k][l + 1] - 1] == 1:
				sum += 1
		if sum % 2 != p[k]:
			break
	else:
		count += 1
print(count)


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	t = 0
	for j in range(m):
		o = sum((1 for h in k[j][1:] if i >> h - 1 & 1))
		if o % 2 == p[j]:
			t += 1
	if t == m:
		ans += 1
print(ans)


f = lambda : map(int, input().split())
(n, m) = f()
ll = [[0] * n for i in range(m)]
for i in range(m):
	(_, *t) = f()
	for j in t:
		ll[i][j - 1] = 1
lp = list(f())
import itertools as it
ans = 0
for p in it.product([0, 1], repeat=n):
	if lp == [sum((a * b for (a, b) in zip(p, l))) % 2 for l in ll]:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
K = []
for i in range(M):
	K.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	flg = True
	for j in range(M):
		n = 0
		for k in K[j][1:]:
			n += i >> k - 1 & 1
		if n % 2 != p[j]:
			flg = False
			break
	if flg:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
swiches = []
for _ in range(M):
	swiches.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
temp = '0' + str(N) + 'b'
case = []
for i in range(2 ** N):
	case.append(format(i, temp))
for a in range(len(swiches)):
	for b in range(len(swiches[a])):
		swiches[a][b] -= 1
ans = 0
for x in case:
	flag = 0
	for i in range(M):
		temp = 0
		for j in swiches[i]:
			temp += int(x[j])
		if temp % 2 == p[i]:
			flag += 1
	if flag == M:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
S = [list(map(int, input().split())) for i in range(m)]
P = list(map(int, input().split()))
c = 0
a = 0
for a in range(2 ** n):
	a2 = format(a, 'b').zfill(n)
	d = 0
	for i in range(m):
		o = 0
		for j in range(S[i][0]):
			o += int(a2[S[i][j + 1] - 1])
		if o % 2 == P[i]:
			d += 1
	if d == m:
		c += 1
print(c)


(N, M) = map(int, input().split())
S = []
for i in range(M):
	k = list(map(int, input().split()))
	S.append(k[1:])
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	a = 0
	for j in range(M):
		t = 0
		for s in S[j]:
			t += i >> s - 1 & 1
		if t % 2 == P[j]:
			a += 1
	if a == M:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
sw = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

def mask(l):
	m = 0
	for i in l:
		m += 2 ** (i - 1)
	return m
masks = list(map(mask, sw))
ret = 0
for i in range(2 ** N):
	if all((bin(i & m).count('1') % 2 == p for (m, p) in zip(masks, P))):
		ret += 1
print(ret)


(n, m) = map(int, input().split())
s_lists = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
count = 0
for i in range(2 ** n):
	l = 1
	for (p, S) in zip(P, s_lists):
		l *= sum([int(bin(i)[2:].zfill(n)[s - 1]) for s in S]) % 2 == p
	count += l
print(count)


(N, M) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))
cnt = 0
for i in range(2 ** N):
	for k in range(M):
		tmp = 0
		for j in range(N):
			if i >> j & 1 and j + 1 in s[k]:
				tmp += 1
		if tmp % 2 != p[k]:
			break
	else:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	s = bin(i)[2:].zfill(n)
	f = True
	for j in range(m):
		x = k[j]
		c = 0
		for h in x:
			if s[h - 1] == '0':
				c += 1
		if c % 2 != p[j]:
			f = False
	if f:
		ans += 1
print(ans)


from itertools import product
(N, M) = list(map(int, input().split()))
k = []
S = []
for _ in range(M):
	ks = list(map(int, input().split()))
	k.append(ks[0])
	S.append(ks[1:])
p = list(map(int, input().split()))
onoff = list(product([0, 1], repeat=N))
ans = 0
for i in onoff:
	cnt = 0
	for (ind, s) in enumerate(S):
		state = 0
		for o in s:
			state += i[o - 1]
		if state % 2 == p[ind]:
			cnt += 1
	if cnt == M:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
l = []
for i in range(1 << n):
	tmp = str(bin(i))[2:]
	l.append(tmp.zfill(n))
K = [list(map(int, input().split())) for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for i in range(len(l)):
	O = []
	for j in range(m):
		ON = 0
		for ii in range(K[j][0]):
			if l[i][K[j][ii + 1] - 1] == '1':
				ON += 1
		if ON % 2 == P[j]:
			O.append(1)
		else:
			O.append(0)
	if sum(O) == m:
		ans += 1
print(ans)


(n, m) = (int(_) for _ in input().split())
l = [list((int(_) for _ in input().split())) for i in range(m)]
p = list(map(int, input().split()))
l = [i[1:] for i in l]
res = 0
for i in range(2 ** n):
	x = bin(i)[2:][-n:].zfill(n)
	if all([sum([int(x[ii - 1]) for ii in l[i]]) % 2 == p[i] for i in range(len(l))]):
		res += 1
print(res)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	flag = True
	for j in range(m):
		res = 0
		for k in ks[j][1:]:
			res += i // 2 ** (k - 1) & 1
		if res % 2 != p[j]:
			flag = False
	if flag == True:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	num = 0
	for j in range(m):
		cnt = 0
		for k in range(1, l[j][0] + 1):
			if i >> l[j][k] - 1 & 1:
				cnt += 1
		if cnt % 2 == p[j]:
			num += 1
	if num == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for bit in range(2 ** n):
	ok = True
	for j in range(m):
		c = 0
		k = s[j][0]
		for l in range(1, k + 1):
			if bit & 1 << s[j][l] - 1:
				c += 1
		if c % 2 != p[j]:
			ok = False
	if ok:
		ans += 1
print(ans)


import itertools
(N, M) = map(int, input().split())
Switch = []
for i in range(M):
	Swi = list(map(int, input().split()))
	S = Swi[0]
	Switch.append(Swi[1:S + 1])
Plist = list(map(int, input().split()))
Ans = 0
L = [0, 1]
c_list = list(itertools.product(L, repeat=N))
for comb in c_list:
	for i in range(M):
		Jud = 0
		Swi = Switch[i]
		for j in Swi:
			Jud += comb[j - 1]
		if Jud % 2 != Plist[i]:
			break
		elif i == M - 1:
			Ans += 1
print(Ans)


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return map(int, input().split())

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(N, M) = i_map()
	K = []
	for i in range(M):
		l = i_list()
		l.pop(0)
		K.append(l)
	P = i_list()
	cnt = 0
	for i in range(2 ** N):
		trial = []
		for j in range(N):
			if i >> j & 1:
				trial.append(1)
			else:
				trial.append(0)
		flg = True
		for (h, g) in enumerate(K):
			num = 0
			for r in g:
				if trial[r - 1] == 1:
					num += 1
			if num % 2 != P[h]:
				flg = False
		if flg == True:
			cnt += 1
	print(cnt)

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in [0] * M]
(*p,) = map(int, input().split())
ans = 0
for i in range(1 << N):
	S = [i & 1 << j > 0 for j in range(N)]
	tmp = 0
	for (j, ks1) in enumerate(ks):
		(k, *s) = ks1
		tmp = sum((S[c - 1] for c in s))
		if tmp % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
bulbbit = [0] * m
for i in range(m):
	tmp = list(map(int, input().split()))
	for j in range(1, tmp[0] + 1):
		bulbbit[i] |= 1 << tmp[j] - 1
p = list(map(int, input().split()))
ans = 0
for s in range(1 << n):
	cnt = 0
	for i in range(m):
		swon = 0
		for j in range(n):
			if s >> j & 1 and bulbbit[i] >> j & 1:
				swon += 1
		if swon % 2 == p[i]:
			cnt += 1
	if cnt == m:
		ans += 1
print(ans)


from itertools import product
(n, m) = map(int, input().split())
switch = []
for i in range(m):
	(k, *s) = map(int, input().split())
	s = list(s)
	switch.append(s)
p = list(map(int, input().split()))
ans = 0
for i in product(range(2), repeat=n):
	flag = True
	for s in range(m):
		cnt = 0
		for t in switch[s]:
			if i[t - 1] == 1:
				cnt += 1
		if cnt % 2 != p[s]:
			flag = False
			break
	if flag == True:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
s_lst = [[False] * N for _ in range(M)]
for i in range(M):
	ks = list(map(int, input().split()))
	for (j, value) in enumerate(ks):
		if j != 0:
			s_lst[i][value - 1] = True
p = list(map(int, input().split()))
ans = 0
for bit in range(2 ** N):
	cnt = [0] * M
	for i in range(N):
		if bit >> i & 1 == 1:
			for j in range(M):
				if s_lst[j][i]:
					cnt[j] += 1
	flug = True
	for i in range(M):
		if cnt[i] % 2 != p[i]:
			flug = False
	if flug:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
light = [list(map(int, input().split())) for _ in range(m)]
lighton = list(map(int, input().split()))
swicth = []
for i in range(2 ** n):
	a = [0] * n
	for j in range(n):
		if i >> j & 1:
			a[j] = 1
	swicth.append(a)
ans = 0
for x in swicth:
	for y in range(m):
		b = light[y][1:]
		total = 0
		for z in b:
			total += x[z - 1]
		if total % 2 != lighton[y]:
			break
	else:
		ans += 1
print(ans)


def light(l, i):
	k = 1 << i - 1
	if l & k:
		return 1
	else:
		return 0
(N, M) = map(int, input().split())
s = list()
for j in range(0, M):
	s.append(0)
for j in range(0, M):
	s[j] = list(map(int, input().split()))
p = list(map(int, input().split()))
a = 0
for l in range(0, 1 << N):
	b = 0
	for j in range(0, M):
		c = 0
		for i in range(1, s[j][0] + 1):
			c += light(l, s[j][i])
		if c % 2 == p[j]:
			b += 1
	if b == M:
		a += 1
print(a)


import itertools
(N, M) = list(map(int, input().split()))
A = []
for m in range(M):
	a = list(map(int, input().split()))
	A.append(a[1:])
P = list(map(int, input().split()))
S = itertools.product([0, 1], repeat=N)
ans = 0
for s in S:
	flag = True
	for i in range(M):
		temp = 0
		for a in A[i]:
			temp += s[a - 1]
		if temp % 2 != P[i]:
			flag = False
	if flag == True:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
cnt = 0
for i in range(2 ** N):
	flag = True
	for j in range(M):
		if not [i >> k - 1 & 1 for k in s[j]].count(1) % 2 == p[j]:
			flag = False
	if flag:
		cnt += 1
print(cnt)


(N, M) = map(int, input().split())
K = [set(list(map(int, input().split()))[1:]) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	S = set([1 + j for j in range(N) if 2 ** j & i])
	for (j, k) in enumerate(K):
		if len(S.intersection(k)) % 2 != P[j]:
			break
	else:
		ans += 1
print(ans)


from itertools import product
(n, m) = map(int, input().split())
l = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
c = 0
for sw in product((0, 1), repeat=n):
	for i in range(m):
		if sum((sw[si - 1] for si in l[i][1:])) % 2 != p[i]:
			break
	else:
		c += 1
print(c)


(n, m) = map(int, input().split())
s = []
for _ in range(m):
	tmp = list(map(int, input().split()))
	s.append(tmp[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	for j in range(m):
		count = 0
		check = True
		for k in s[j]:
			if i >> k - 1 & 1:
				count += 1
		if count % 2 != p[j]:
			check = False
			break
	if check:
		ans += 1
print(ans)


from itertools import product
(N, M) = map(int, input().split())
S = []
for _ in range(M):
	(_, *s) = map(int, input().split())
	S.append(s)
P = [int(s) for s in input().split()]
cnt = 0
for ss in product([0, 1], repeat=N):
	for i in range(M):
		if sum((ss[sj - 1] for sj in S[i])) % 2 != P[i]:
			break
	else:
		cnt += 1
print(cnt)


(N, M) = map(int, input().split())
s = [list(map(lambda x: int(x) - 1, input().split()[1:])) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	bulb_num = 0
	for j in range(M):
		on_num = 0
		for k in range(N):
			if i >> k & 1 and k in s[j]:
				on_num += 1
		if (on_num - p[j]) % 2 == 0:
			bulb_num += 1
	if bulb_num == M:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	p = []
	for s in S:
		tmp = 0
		for ss in s:
			if i >> N - ss & 1:
				tmp += 1
		p.append(tmp % 2)
	if p == P:
		ans += 1
print(ans)


((n, m), *s, p) = [list(map(int, t.split())) for t in open(0)]
a = 0
for i in range(1 << n):
	c = [0] * m
	for j in range(n * m):
		c[j % m] ^= i >> j // m & (j // m + 1 in s[j % m][1:])
	a += c == p
print(a)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
a = [bin(j)[2:].zfill(n) for j in range(2 ** n)]
ans = 0
for jj in range(2 ** n):
	b = 0
	for i in range(m):
		num = 0
		for ii in range(1, s[i][0] + 1):
			num += int(a[jj][s[i][ii] - 1])
		if num % 2 != p[i]:
			b += 1
	if b == 0:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
k = []
for i in range(m):
	k.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
a = 0
for i in range(2 ** n):
	i = list(map(int, list(bin(i)[2:].zfill(n))))
	for j in range(m):
		x = p[j]
		for l in k[j]:
			x ^= i[l - 1]
		if x == 1:
			break
	else:
		a += 1
print(a)


(N, M) = map(int, input().split())
lights = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	onoff = bin(i)[2:].zfill(N)
	for (j, switches) in enumerate(lights):
		if sum((onoff[s - 1] == '1' for s in switches[1:])) % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
K = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(0, 2 ** N):
	S = [0] * M
	for j in range(M):
		for k in range(N):
			if i >> k & 1 and k + 1 in K[j]:
				S[j] += 1
	S = [i % 2 for i in S]
	if S == P:
		ans += 1
print(ans)


import math
(N, M) = list(map(int, input().split()))
switch = [0] * N
pattern = 2 ** N
ans = 0
for i in range(M):
	temp = input().split()[1:]
	for j in temp:
		switch[int(j) - 1] += 1 << i
p = list(map(int, input().split()))
pbin = 0
temp = 1
for i in p:
	pbin += i * temp
	temp *= 2
for i in range(pattern):
	temp = 0
	j = 0
	while i > 0:
		if i & 1 == 1:
			temp = temp ^ switch[j]
		j += 1
		i = i >> 1
	if pbin == temp:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
K = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	bit = [i >> j & 1 for j in range(n)]
	for (j, k) in enumerate(K):
		if p[j] != sum([bit[l - 1] for l in k]) % 2:
			break
	else:
		ans += 1
print(ans)


import itertools
(N, M) = map(int, input().split())
L = [list(map(int, input().split()))[1:] for i in range(M)]
P = list(map(int, input().split()))
A = list(itertools.product([0, 1], repeat=N))
ans = 2 ** N
for i in range(2 ** N):
	for j in range(M):
		cnt = 0
		for k in L[j]:
			cnt += A[i][k - 1]
		if P[j] != cnt % 2:
			ans -= 1
			break
print(ans)


(n, m) = map(int, input().split())
sws = []
for _ in range(m):
	sws.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	for j in range(m):
		t = 0
		for sw in sws[j]:
			if i >> sw - 1 & 1:
				t += 1
		if t % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	onoffs = [int(j) for j in list(bin(i)[2:].zfill(n))]
	Flag = True
	for lamp in range(m):
		k = a[lamp][0]
		info = [l - 1 for l in a[lamp][1:]]
		tmp = 0
		for index in info:
			if onoffs[index]:
				tmp += 1
		if tmp % 2 != p[lamp]:
			Flag = False
			break
	if Flag:
		ans += 1
print(ans)


import itertools
(N, M) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for item in itertools.product(range(2), repeat=N):
	if all((sum((item[x - 1] for x in L[i][1:])) % 2 == P[i] for i in range(M))):
		ans += 1
print(ans)


(n, m) = map(int, input().split())
A = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	num = format(i, 'b').zfill(n)
	point = 0
	for j in range(m):
		cnt = 0
		for k in A[j]:
			if num[k - 1] == '1':
				cnt += 1
		if cnt % 2 == P[j]:
			point += 1
	if point == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
p = 2
from itertools import product
iterator = product(range(p), repeat=n)
s = [0 for i in range(m)]
for i in range(m):
	S = list(map(int, input().split()))
	k = S[0]
	s[i] = S[1:]
p = list(map(int, input().split()))
ans = 0
for idxs in iterator:
	tmp1 = 0
	for i in range(m):
		tmp2 = 0
		for j in s[i]:
			tmp2 += idxs[j - 1]
		if tmp2 % 2 == p[i]:
			tmp1 += 1
	if tmp1 == m:
		ans += 1
print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
(N, M) = map(int, input().split())
lamps = [list(map(lambda x: int(x) - 1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for lamp in range(M):
		on_sum = 0
		for j in range(N):
			if i >> j & 1 and j in lamps[lamp]:
				on_sum += 1
		if on_sum % 2 != p[lamp]:
			break
	else:
		ans += 1
print(ans)


ks = []
(n, m) = map(int, input().split())
for i in range(m):
	ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans_ans = 0
for i in range(2 ** n):
	num = '0' * 10 + bin(i)
	ans = 0
	for j in range(m):
		cnt = 0
		for k in range(n):
			if num[-k - 1] == '1' and k + 1 in ks[j][1:]:
				cnt += 1
		if cnt % 2 == p[j]:
			ans += 1
	if ans == m:
		ans_ans += 1
print(ans_ans)


from itertools import combinations
(n, m) = map(int, input().split())
ksm = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
onoff = [0] * n
total = 0

def dfs(i, onoff):
	nonlocal total
	if i == n:
		flag = True
		for (idx, j) in enumerate(ksm):
			count = 0
			for k in j[1:]:
				count += onoff[k - 1]
			if count % 2 != p[idx]:
				flag = False
		if flag:
			total += 1
		return
	dfs(i + 1, onoff[:])
	dfs(i + 1, onoff[:i] + [1] + onoff[i + 1:])
dfs(0, onoff)
print(total)


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
t = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	bit = [i >> j & 1 for j in range(n)]
	for (k, x) in enumerate(s):
		if t[k] != sum([bit[y - 1] for y in x[1:]]) % 2:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
L = []
for i in range(m):
	l = list(map(int, input().split()))
	s = 0
	for j in range(l[0]):
		s += 2 ** (l[j + 1] - 1)
	L.append(s)
P = list(map(int, input().split()))
r = 0
for i in range(1 << n):
	p = 0
	for j in range(m):
		if bin(i & L[j]).count('1') % 2 == P[j]:
			p += 1
	if p == m:
		r += 1
print(r)


from itertools import product
(n, m) = map(int, input().split())
KS = [list(map(int, input().split())) for _ in range(m)]
P = list(map(int, input().split()))
count = 0
for S in product((0, 1), repeat=n):
	if all((sum((S[s - 1] for s in ks[1:])) % 2 == p for (p, ks) in zip(P, KS))):
		count += 1
print(count)


def ma():
	(n, m) = map(int, input().split())
	ans = 0
	e = [set(list(map(int, input().split()))[1:]) for i in range(m)]
	f = list(map(int, input().split()))
	for i in range(2 ** n):
		l = {a for (a, b) in zip(range(1, n + 1), bin(i)[2:].zfill(n)) if b == '1'}
		if sum([int(len(e[j - 1] & l) % 2 != f[j - 1]) for j in range(1, m + 1)]) == 0:
			ans += 1
	print(ans)
ma()


from itertools import islice
R = lambda : map(int, input().split())
(n, m) = R()
a = [list(islice(R(), 1, None)) for _ in range(m)]
p = list(R())
r = sum((all((sum((i >> j - 1 & 1 for j in r)) & 1 == pi for (r, pi) in zip(a, p))) for i in range(1 << n)))
print(r)


(n, m) = list(map(int, input().split(' ')))
k = []
s = []
for i in range(m):
	a = list(map(int, input().split(' ')))
	k.append(a[0])
	s.append(a[1:])
p = list(map(int, input().split(' ')))
ans = 0
for i in range(2 ** n):
	ri_cnt = 0
	for j in range(m):
		sw_cnt = 0
		for l in range(k[j]):
			if i >> s[j][l] - 1 & 1:
				sw_cnt += 1
		if sw_cnt % 2 == p[j]:
			ri_cnt += 1
	if ri_cnt == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	tmp = 0
	f = 1
	for mm in range(m):
		tmp = 0
		for j in info[mm][1:]:
			tmp += int(str(format(i, 'b').zfill(n))[int(j) - 1])
		if tmp % 2 != p[mm]:
			f = 0
	if f == 1:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
ks = [[int(i) for i in input().split()] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	sw = []
	on = 0
	for j in range(n):
		sw.append(i >> j & 1)
	for k in range(m):
		if sum([sw[ks[k][j + 1] - 1] for j in range(ks[k][0])]) % 2 == p[k]:
			on += 1
	if on == m:
		ans += 1
print(ans)


f = lambda : map(int, input().split())
(n, m) = f()
ll = [[0] * n for _ in range(m)]
for l in ll:
	(k, *s) = f()
	for i in s:
		l[i - 1] = 1
p = list(f())
import itertools as it
print(sum((all((sum((a * b for (a, b) in zip(l, t))) % 2 == p[i] for (i, l) in enumerate(ll))) for t in it.product([0, 1], repeat=n))))


(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	ans += 1
	for j in range(len(s)):
		on = 0
		for k in range(s[j][0]):
			on += (i >> s[j][k + 1] - 1) % 2
		if on % 2 != p[j]:
			ans -= 1
			break
print(ans)


(N, M) = map(int, input().split())
S = [0] * M
for i in range(M):
	s = list(map(int, input().split()))
	for j in s[1:]:
		S[i] += 2 ** (j - 1)
p = list(map(int, input().split()))
ans = 0
for b in range(2 ** N):
	tmp = True
	for (i, s) in enumerate(S):
		tmp &= bin(b & s).count('1') % 2 == p[i]
	if tmp:
		ans += 1
print(ans)


all_input = []
while True:
	try:
		all_input.append(list(map(int, input().split())))
	except:
		break
(N, M) = (all_input[0][0], all_input[0][1])
p = all_input[-1]
(all_input.pop(0), all_input.pop(-1))
switch = [all_input[i][1:] for i in range(M)]
num_switch = [all_input[i][0] for i in range(M)]
all_on = 0
for i in range(2 ** N):
	num_light_on = 0
	for m in range(M):
		switch_on = 0
		for j in range(N):
			if i >> j & 1:
				if j + 1 in switch[m]:
					switch_on += 1
		if switch_on % 2 == p[m]:
			num_light_on += 1
	if num_light_on == M:
		all_on += 1
print(all_on)


from itertools import combinations

def getval():
	(n, m) = map(int, input().split())
	s = [list(map(int, input().split())) for i in range(m)]
	for i in range(m):
		for j in range(1, s[i][0] + 1):
			s[i][j] -= 1
	p = list(map(int, input().split()))
	return (n, m, s, p)

def main(n, m, s, p):
	l = [[] for i in range(n)]
	for i in range(m):
		for j in range(1, s[i][0] + 1):
			l[s[i][j]].append(i)
	ans = 0
	for i in range(n + 1):
		for c in combinations(range(n), i):
			temp = [0 for i in range(m)]
			for j in c:
				for k in l[j]:
					temp[k] += 1
					temp[k] %= 2
			if temp == p:
				ans += 1
	print(ans)

def __starting_point():
	(n, m, s, p) = getval()
	main(n, m, s, p)
__starting_point()


(n, m) = map(int, input().split())
(k, s) = ([], [])
for i in range(m):
	inp = list(map(int, input().split()))
	(k_, s_) = (inp[0], inp[1:])
	k.append(k_)
	s.append(s_)
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
	flg = True
	for i in range(m):
		cnt = 0
		for e in s[i]:
			e -= 1
			if bit & 1 << e:
				cnt += 1
		if cnt % 2 != p[i]:
			flg = False
	if flg:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [0] * n
for i in range(m):
	k = list(map(int, input().split()))
	for j in range(1, k[0] + 1):
		s[k[j] - 1] |= 1 << i
p = 0
k = list(map(int, input().split()))
for i in range(m):
	p |= k[i] << i
ans = 0
for i in range(1 << n):
	t = 0
	for j in range(n):
		if i >> j & 1:
			t ^= s[j]
	if t == p:
		ans += 1
print(ans)


N = None
M = None
S = []
P = []

def __starting_point():
	(N, M) = map(int, input().split())
	for _ in range(M):
		row = list(map(int, input().split()))[1:]
		S.append(row)
	P = list(map(int, input().split()))
	ans = 0
	for bit in range(1 << N):
		on_switches = []
		light = 0
		for i in range(N):
			if bit >> i & 1:
				on_switches.append(i)
		for i in range(M):
			cnt = 0
			for s in S[i]:
				for on_switch in on_switches:
					if s == on_switch + 1:
						cnt += 1
			if cnt % 2 == P[i]:
				light += 1
		if light == M:
			ans += 1
	print(ans)
__starting_point()


(N, M) = list(map(int, input().split()))
S = [0] * M
answer = 0
for i in range(M):
	S[i] = list(map(int, input().split()))
P = list(map(int, input().split()))
for i in range(2 ** N):
	mb = '0' + str(N) + 'b'
	bi = format(i, mb)
	count = 0
	for j in range(M):
		on = 0
		for k in range(S[j][0]):
			on += int(bi[-S[j][k + 1]])
		if on % 2 == P[j]:
			count += 1
	if count == M:
		answer += 1
print(answer)


from itertools import product
(n, m) = map(int, input().split())
switches = []
for _ in range(m):
	x = list(map(int, input().split()))[1:]
	temp = []
	for i in range(n):
		if i + 1 in x:
			temp.append(1)
		else:
			temp.append(0)
	switches.append(temp)
p = list(map(int, input().split()))
ans = 0
for on_off in product([1, 0], repeat=n):
	flag = 1
	for (i, switch) in enumerate(switches):
		cnt = 0
		for (x, y) in zip(on_off, switch):
			if x == 1 and y == 1:
				cnt += 1
		if cnt % 2 != p[i]:
			flag = 0
	if flag:
		ans += 1
print(ans)


(N, M) = [int(_) for _ in input().split()]
KS = [[int(_) for _ in input().split()] for i in range(M)]
p = [int(_) for _ in input().split()]
result = 0

def check(i, j):
	x = sum((i >> s - 1 & 1 for s in KS[j][1:]))
	return x % 2 == p[j]
for i in range(2 ** N):
	result += all((check(i, j) for j in range(M)))
print(result)


(n, m) = map(int, input().split())
li = []
for i in range(m):
	a = list(map(int, input().split()))
	li.append(a[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	ok = 1
	s = []
	for j in range(n):
		if i >> j & 1:
			s.append(j)
	for j in range(m):
		tmp = 0
		for k in li[j]:
			if k - 1 in s:
				tmp += 1
		if tmp % 2 != p[j]:
			ok = 0
	if ok:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = []
for _ in range(M):
	S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
	for m in range(M):
		if sum([bit & 1 << s - 1 > 0 for s in S[m]]) % 2 != P[m]:
			break
	else:
		ans += 1
print(ans)


def f(i):
	if i == n:
		on = [0] * m
		for j in range(m):
			for k in range(1, s[j][0] + 1):
				if t[s[j][k] - 1]:
					on[j] += 1
		for j in range(m):
			if not on[j] % 2 == p[j]:
				return
		nonlocal ans
		ans += 1
		return
	t[i] = 1
	f(i + 1)
	t[i] = 0
	f(i + 1)
	return
(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
t = [0] * n
f(0)
print(ans)


(n, m) = map(int, input().split())
ks = []
ss = []
for _ in range(m):
	row = list(map(lambda x: int(x) - 1, input().split()))
	ks.append(row[0] + 1)
	ss.append(row[1:])
ps = list(map(int, input().split()))

def is_bulb_on(bits, i):
	cnt = 0
	for s in ss[i]:
		if bits[s]:
			cnt += 1
	return cnt % 2 == ps[i]

def are_all_bulb_on(bits):
	good = True
	i = 0
	while good and i < m:
		good &= is_bulb_on(bits, i)
		i += 1
	return good

def rec(bits, i):
	if i == n:
		return 1 if are_all_bulb_on(bits) else 0
	cnt = 0
	cnt += rec(bits, i + 1)
	bits[i] = 1
	cnt += rec(bits, i + 1)
	bits[i] = 0
	return cnt
bits = [0] * n
print(rec(bits, 0))


from itertools import product
(n, m) = list(map(int, input().split()))
S = []
for _ in range(m):
	(k, *s) = list(map(int, input().split()))
	S.append(s)
p = list(map(int, input().split()))
ans = 0
for pattern in product(range(2), repeat=n):
	for (x, y) in zip(S, p):
		on_cnt = sum([pattern[s - 1] == 1 for s in x])
		if on_cnt % 2 != y:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
res1 = 0
for i in range(2 ** n):
	res2 = 0
	for j in range(m):
		cnt = 0
		for s in range(ks[j][0]):
			if i >> ks[j][s + 1] - 1 & 1:
				cnt += 1
		if cnt % 2 == p[j]:
			res2 += 1
	if res2 == m:
		res1 += 1
print(res1)


(n, m) = map(int, input().split())
S = []
for _ in range(m):
	s = list(map(int, input().split()))
	S.append(s[1:])
P = tuple(map(int, input().split()))
ans = 0
for i in range(1 << n):
	for j in range(m):
		cnt = 0
		for k in S[j]:
			if i & 1 << k - 1:
				cnt += 1
		if cnt % 2 != P[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
cs = [list(map(int, input().split())) for _ in range(m)]
ps = list(map(int, input().split()))
ans = 0
for on in range(2 ** n):
	patern = bin(on)[2:].rjust(n, '0')
	ok = True
	for i in range(m):
		ct = 0
		for j in range(cs[i][0]):
			if patern[cs[i][j + 1] - 1] == '1':
				ct += 1
		if ct % 2 != ps[i]:
			ok = False
	if ok:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
A = [list(map(lambda x: int(x) - 1, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	for j in range(m):
		cnt = 0
		for k in range(n):
			if i >> k & 1 and k in A[j]:
				cnt += 1
		if cnt % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


import sys
input = sys.stdin.readline

def I():
	return int(input())

def MI():
	return list(map(int, input().split()))

def LI():
	return list(map(int, input().split()))
(n, m) = MI()
sws = []
for i in range(m):
	sws.append(list(map(int, input().split())))
ps = LI()
ans = 0
for i in range(2 ** n):
	count = 0
	for j in range(m):
		sm = 0
		for k in range(1, len(sws[j])):
			sm += (i >> sws[j][k] - 1) % 2
		if sm % 2 == ps[j]:
			count += 1
	if count == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
km = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	flag = True
	for j in range(m):
		c = 0
		for k in km[j][1:]:
			if i & 2 ** (k - 1):
				c += 1
		if c % 2 != p[j]:
			flag = False
	if flag:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	flag = True
	for j in range(m):
		on = 0
		a = False
		for l in ks[j]:
			if a and i >> l - 1 & 1:
				on += 1
			a = True
		if on % 2 != p[j]:
			flag = False
			break
	if flag:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = []
for _ in range(m):
	(_, *t) = map(int, input().split())
	s.append(t)
(*p,) = map(int, input().split())
print(sum([all([sum([i >> u - 1 for u in s[j]]) % 2 == p[j] for j in range(m)]) for i in range(2 ** n)]))


(n, m) = map(int, input().split())
s = []
for _ in range(m):
	ks = list(map(int, input().split()))
	s.append(ks[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	for (x, y) in zip(s, p):
		flag = False
		for a in x:
			if i & 1 << a - 1:
				flag = not flag
		if int(flag) != y:
			break
	else:
		ans += 1
print(ans)


import itertools
(n, m) = map(int, input().split())
L = []
for i in range(m):
	(a, *l) = map(int, input().split())
	L += [l]
S = list(map(int, input().split()))
ans = 0
for i in itertools.product([0, 1], repeat=n):
	f = 0
	for (l, s) in zip(L, S):
		ls = 0
		for ll in l:
			ls += i[ll - 1]
		if ls % 2 == s:
			f += 1
	if f == m:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	good = True
	for j in range(m):
		cur = 0
		for e in s[j][1:]:
			if i & 1 << e - 1:
				cur += 1
		if cur % 2 != p[j]:
			good = False
			break
	if good:
		ans += 1
print(ans)


(n, m) = [int(i) for i in input().split()]
ks = [[int(i) for i in input().split()] for _ in range(m)]
p = [int(i) for i in input().split()]
cnt = 0
for i in range(2 ** n):
	on = set((j + 1 for j in range(n) if i >> j & 1 == 1))
	flag = True
	for j in range(m):
		(_, *s) = ks[j]
		flag &= len(on & set(s)) % 2 == p[j]
	cnt += flag
print(cnt)


(n, m) = map(int, input().split())
ks = [[] for i in range(m)]
for i in range(m):
	ks[i] = list(map(lambda x: int(x) - 1, input().split()))
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	l = [0] * n
	for j in range(n):
		l[j] = 1 if i >> j & 1 else 0
	for j in range(m):
		s = sum([l[k] for k in ks[j][1:]])
		if s % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
sw = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	f = 1
	for j in range(m):
		c = 0
		for x in sw[j][1:]:
			x -= 1
			c += i >> x & 1
		if c % 2 != p[j]:
			f = 0
	ans += 1 if f else 0
print(ans)


(N, M) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
import itertools
import operator
import functools
print(sum((1 for i in itertools.product([True, False], repeat=N) if functools.reduce(operator.and_, [functools.reduce(operator.xor, [i[j - 1] for j in k[l][1:]]) == p[l] for l in range(M)]))))


(N, M) = map(int, input().split())
S = []
for m in range(M):
	nums = list(map(int, input().split()))
	S.append(nums[1:])
p = list(map(int, input().split()))
ans = 0
for bits in range(1 << N):
	for m in range(M):
		on = 0
		for s in S[m]:
			on += bits >> s - 1 & 1
		if on & 1 != p[m]:
			break
	else:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
l = []
for i in range(M):
	l.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	isOK = True
	for j in range(M):
		stat = 0
		for k in l[j]:
			k -= 1
			if i & 1 << k:
				stat = (stat + 1) % 2
		if stat != p[j]:
			isOK = False
	if isOK:
		ans += 1
print(ans)


import itertools
(N, M) = [int(_) for _ in input().split()]
KS = [[int(_) - 1 for _ in input().split()] for _ in range(M)]
P = [int(_) for _ in input().split()]
ans = 0
for switches in itertools.product(range(2), repeat=N):
	f = all((sum((switches[s] for s in ks[1:])) % 2 == P[i] for (i, ks) in enumerate(KS)))
	ans += f
print(ans)


(N, M) = map(int, input().split())
L = []
for _ in range(M):
	(k, *S) = map(int, input().split())
	L.append(S)
P = list(map(int, input().split()))
c = 0
for i in range(2 ** N):
	A = []
	for j in range(N):
		if i >> j & 1:
			A.append(j + 1)
	A = set(A)
	for i in range(M):
		if len(A & set(L[i])) % 2 != P[i]:
			break
	else:
		c += 1
print(c)


(n, m) = map(int, input().split())
swithes = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
total = 0
for i in range(2 ** n):
	bag = []
	ans = 0
	for j in range(n):
		if i >> j & 1:
			bag.append(j + 1)
	for k in range(m):
		a = 0
		for l in range(swithes[k][0]):
			if swithes[k][l + 1] in bag:
				a += 1
		if a % 2 == p[k]:
			ans += 1
	if ans == m:
		total += 1
print(total)


(n, m) = map(int, input().split())
X = []
for _ in range(m):
	(k, *A) = list(map(int, input().split()))
	b = 0
	for a in A:
		b += 1 << a - 1
	X.append(b)
P = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	for (x, p) in zip(X, P):
		y = i & x
		c = bin(y).count('1') % 2
		if c != p:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))
c = 0
from itertools import product
for i in product([0, 1], repeat=n):
	if all((len([None for t in t if i[t - 1]]) % 2 == p[j] for (j, t) in enumerate(s))):
		c += 1
print(c)


(N, M) = map(int, input().split())
conditions = []
for i in range(M):
	conditions.append(list(map(int, input().split()))[1:])
compair = list(map(int, input().split()))
master_list = []
for i in range(2 ** N):
	target = list(map(int, '{:010b}'.format(i)))[-N:]
	master_list.append(target)
result_list = []
for i in master_list:
	prepair_line = []
	for j in conditions:
		total = 0
		for k in j:
			total += i[k - 1]
		prepair_line.append(total % 2)
	result_list.append(prepair_line)
cnt = 0
for i in result_list:
	if compair == i:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for i in range(m)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	for (s, p) in zip(S, P):
		c = 0
		for t in s:
			if i >> t - 1 & 1:
				c += 1
		if c % 2 != p:
			break
	else:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	s = 0
	for j in range(m):
		c = 0
		for k in range(len(ks[j]) - 1):
			if i >> ks[j][k + 1] - 1 & 1:
				c += 1
		if c % 2 == p[j]:
			s += 1
	if s == m:
		ans += 1
print(ans)


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key
from bisect import bisect_left
INF = 1001001001
__MOD__ = 10 ** 9 + 7
yn = 'YNeos'
judge = False
cnt = 0
ans = None

def lcm(a, b):
	return a * b // gcd(a, b)

def intinput():
	return int(input())

def mulinputs():
	return list(map(int, input().split()))

def lineinputs(func=intinput):
	datas = []
	while True:
		try:
			datas.append(func())
		except EOFError:
			break
	return datas

def bindex(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return None

class UnionFind:

	def __init__(self, n):
		self.r = [-1] * (n + 1)

	def root(self, x):
		if self.r[x] < 0:
			return x
		self.r[x] = self.root(self.r[x])
		return self.r[x]

	def unite(self, x, y):
		x = self.root(x)
		y = self.root(y)
		if x == y:
			return False
		if self.r[x] > self.r[y]:
			(x, y) = (y, x)
		self.r[x] += self.r[y]
		self.r[y] = x
		return True

	def size(self, x):
		return -1 * self.r[self.root(x)]

class ModInt:

	def __init__(self, x):
		self.__x = x % __MOD__

	def __add__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__((self.__x + other.__x) % __MOD__))
		elif type(other) == ModInt:
			return self.__class__((self.__x + other.__x) % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __radd__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__((other.__x + self.__x) % __MOD__))
		elif type(other) == ModInt:
			return self.__class__((other.__x + self.__x) % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __sub__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__((self.__x - other.__x) % __MOD__))
		elif type(other) == ModInt:
			return self.__class__((self.__x - other.__x) % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __rsub__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__((other.__x - self.__x) % __MOD__))
		elif type(other) == ModInt:
			return self.__class__((other.__x - self.__x) % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __mul__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(self.__x * other.__x % __MOD__))
		elif type(other) == ModInt:
			return self.__class__(self.__x * other.__x % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __rmul__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(other.__x * self.__x % __MOD__))
		elif type(other) == ModInt:
			return self.__class__(other.__x * self.__x % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __truediv__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(self.__x * other.__modinv() % __MOD__))
		elif type(other) == ModInt:
			return self.__class__(self.__x * other.__modinv() % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __rtruediv__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(other.__x * self.__modinv() % __MOD__))
		elif type(other) == ModInt:
			return self.__class__(other.__x * self.__modinv() % __MOD__)
		else:
			raise Exception('Not Int or Not ModInt')

	def __pow__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
		elif type(other) == ModInt:
			return self.__class__(pow(self.__x, other.__x, __MOD__))
		else:
			raise Exception('Not Int or Not ModInt')

	def __rpow__(self, other):
		if type(other) == int:
			other = self.__class__(other)
			return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
		elif type(other) == ModInt:
			return self.__class__(pow(other.__x, self.__x, __MOD__))
		else:
			raise Exception('Not Int or Not ModInt')

	def __modinv(self, m=__MOD__):
		a = self.__x
		if a == 0:
			raise ZeroDivisionError()
		if gcd(a, m) != 1:
			raise Exception('%sの逆数は求まりません。' % a)
		(b, u, v) = (m, 1, 0)
		while b != 0:
			t = a // b
			a -= t * b
			(a, b) = (b, a)
			u -= t * v
			(u, v) = (v, u)
		u %= m
		if u < 0:
			u += m
		return u

	def __int__(self):
		return self.__x

	def __str__(self):
		return str(self.__x)

def __starting_point():
	(N, M) = mulinputs()
	(ks, ss, ps) = ([], [], [])
	for _ in range(M):
		(k, *s) = list(mulinputs())
		ks.append(k)
		ss.append(s)
	ps = list(mulinputs())
	cnt = 0
	for n in range(1 << N):
		state = [0] * N
		for j in range(N):
			state[j] = (n & 1 << j) >> j
		is_light = True
		for j in range(M):
			icnt = 0
			for s in ss[j]:
				icnt += state[s - 1]
			if icnt % 2 != ps[j]:
				is_light = False
				break
		if is_light:
			cnt += 1
	print(cnt)
__starting_point()


(N, M) = map(int, input().split())
lamps = [list(map(lambda x: int(x) - 1, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for lamp in range(M):
		on_sum = 0
		for j in range(N):
			if i >> j & 1 and j in lamps[lamp]:
				on_sum += 1
		if on_sum % 2 != p[lamp]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	f = 1
	for j in range(m):
		g = 1
		g &= sum([int(bin(i >> u - 1), 2) for u in s[j]]) % 2 == p[j]
		f &= g
	ans += f
print(ans)


import itertools
(n, m) = list(map(int, input().split()))
L = [list(map(int, input().split()))[1:] for i in range(m)]
P = list(map(int, input().split()))
cnt = 0
for i in range(1 << n):
	k = 1
	for (p, ll) in zip(P, L):
		k *= sum([int(bin(i)[2:].zfill(n)[l - 1]) for l in ll]) % 2 == p
	cnt += k
print(cnt)


(N, M) = map(int, input().split())
S = []
for _ in range(M):
	S.append(list(map(int, input().split()))[1:])
p = list(map(int, input().split()))
ans = 0
for bit in range(1 << N):
	for m in range(M):
		if p[m] != [bin(bit)[2:].zfill(N)[s - 1] for s in S[m]].count('1') % 2:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	val = []
	tmp = i
	for j in range(n):
		val.append(tmp % 2)
		tmp //= 2
	if all((sum((val[k - 1] for k in ks[j][1:])) % 2 == p[j] for j in range(m))):
		ans += 1
print(ans)


(n, m) = map(int, input().split())
li = []
for i in range(m):
	(dk, *d) = list(map(int, input().split()))
	li.append(d)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	sw = bin(i)[2:].zfill(n)
	for j in range(m):
		cnt = 0
		for k in li[j]:
			if sw[k - 1] == '1':
				cnt += 1
		if cnt % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(N, M) = (int(_) for _ in input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for (j, S) in enumerate(A):
		if P[j] ^ sum((i >> k - 1 & 1 for k in S)) & 1:
			break
	else:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
s = [sum([2 ** (i - 1) for i in list(map(int, input().split()))[1:]]) for _ in range(M)]
p = list(map(int, input().split()))
(ans, n) = (0, 2 ** N)
for i in range(n):
	for (s_, p_) in zip(s, p):
		if bin(i & s_).count('1') % 2 != p_:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	judge = True
	switch = ['off' for _ in range(n)]
	for j in range(len(switch)):
		if i >> j & 1:
			switch[j] = 'on'
	for k in range(m):
		count = 0
		for l in range(ks[k][0]):
			if switch[ks[k][l + 1] - 1] == 'on':
				count += 1
		if count % 2 != p[k]:
			judge = False
			break
	if judge == True:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
flgs = [0] * M
for i in range(M):
	(k, *vals) = map(int, input().split())
	for v in vals:
		flgs[i] |= 1 << v - 1
p = list(map(int, input().split()))
cnt = 0
for bit in range(2 ** N):
	cnt_tmp = 1
	for (i, f) in enumerate(flgs):
		if len([j for j in range(N) if f & bit & 1 << j != 0]) % 2 != p[i]:
			cnt_tmp = 0
	cnt += cnt_tmp
print(cnt)


import copy
(n, m) = list(map(int, input().split()))
s = []
for i in range(m):
	st = list(map(int, input().split()))
	s.append([0] + st)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	lst = copy.deepcopy(s)
	flag = True
	for j in range(n):
		if i >> j & 1 == 1:
			for k in lst:
				for l in range(2, k[1] + 2):
					if k[l] - 1 == j:
						k[0] += 1
	for b in range(len(p)):
		if p[b] != lst[b][0] % 2:
			flag = False
	if flag == True:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
A = []
for _ in range(m):
	(k, *s) = map(int, input().split())
	c = 0
	for i in s:
		c += 2 ** (i - 1)
	A.append(c)
P = tuple(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	f = True
	for j in range(m):
		c = bin(i & A[j]).count('1')
		if c % 2 != P[j]:
			f = False
			break
	if f:
		ans += 1
print(ans)


from itertools import product
(n, m) = map(int, input().split())
s = []
for _ in range(m):
	(_, *t) = map(int, input().split())
	s.append(t)
p = [int(i) for i in input().split()]
cnt = 0
for fl in product([0, 1], repeat=n):
	for i in range(m):
		if sum((fl[tmp - 1] for tmp in s[i])) % 2 != p[i]:
			break
	else:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
bulbs = []
ans = 0
for i in range(m):
	c = tuple(map(int, input().split()))
	bulbs.append(c[1:])
p = list(map(int, input().split()))
for i in range(2 ** n):
	cnt = 0
	for (j, bulbs_sub) in enumerate(bulbs):
		switch_on = 0
		for l in bulbs_sub:
			if i >> l - 1 & 1:
				switch_on += 1
		if switch_on % 2 == p[j]:
			cnt += 1
	if cnt == m:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))
cnt = 0
for a in range(2 ** N):
	flag = 1
	for i in range(M):
		if sum([a >> x - 1 & 1 for x in s[i]]) % 2 != p[i]:
			flag = 0
			break
	cnt += flag
print(cnt)


from itertools import product
(n, m) = map(int, input().split())
s = [list(map(lambda x: int(x) - 1, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))
print(sum((all((sum((b[ki] for ki in s[i])) % 2 == p[i] for i in range(m))) for b in product((True, False), repeat=n))))


(N, M) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))
(ans, cnt) = (0, 0)
for n in range(2 ** N):
	for m in range(M):
		cnt = 0
		for i in range(N):
			if n >> i & 1 and i + 1 in s[m]:
				cnt += 1
		if cnt % 2 != p[m]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ks = []
for i in range(m):
	t = list(map(int, input().split()))
	ks.append(t)
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	on = 0
	for j in range(m):
		cnt = 0
		for k in range(ks[j][0]):
			if 1 << ks[j][k + 1] - 1 & i:
				cnt += 1
		if cnt % 2 == p[j]:
			on += 1
		if on == m:
			ans += 1
print(ans)


(N, M) = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	s = i
	b = [0] * N
	for j in range(N):
		if s >= 2 ** (N - j - 1):
			s -= 2 ** (N - j - 1)
			b[j] = 1
	for j in range(M):
		on = 0
		for k in range(ks[j][0]):
			if b[ks[j][k + 1] - 1] == 1:
				on += 1
		if on % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


from itertools import *
(N, M) = map(int, input().split())
K = [list(map(int, input().split()))[1:] for m in range(M)]
P = list(map(int, input().split()))
print(sum([all([sum([s[j - 1] for j in v]) % 2 == t for (v, t) in zip(K, P)]) for s in product([0, 1], repeat=N)]))


(n, m) = map(int, input().split())
swiches = []
for i in range(m):
	s = 0
	for j in list(map(int, input().split()))[1:]:
		s += 2 ** (j - 1)
	swiches.append(s)
pli = list(map(int, input().split()))
cnt = 0
for i in range(2 ** n):
	flag = True
	for (p, s) in zip(pli, swiches):
		if p != bin(i & s).count('1') % 2:
			flag = False
			break
	if flag:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
s = []
for _ in range(m):
	(k, *b) = map(int, input().split())
	s.append(b)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	tr = bin(i)[2:].zfill(n)
	light = 0
	for j in range(m):
		sw = 0
		for l in s[j]:
			if tr[l - 1] == '1':
				sw += 1
		if sw % 2 == p[j]:
			light += 1
	if light == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
A = []
for i in range(m):
	A.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))
ans = 0
for bit in range(1 << n):
	for i in range(m):
		if P[i] != sum([bit >> j - 1 & 1 for j in A[i]]) % 2:
			break
		if i == m - 1:
			ans += 1
print(ans)


(n, m) = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
s = 0
for i in range(2 ** n):
	ok = True
	for k in range(m):
		cnt = 0
		for j in range(n):
			if i >> j & 1:
				if j + 1 in lis[k][1:]:
					cnt += 1
		if cnt % 2 != p[k]:
			ok = False
	if ok:
		s += 1
print(s)


(N, M) = map(int, input().split())
k = []
for i in range(M):
	temp = list(map(int, input().split()))
	k.append(temp[1:])
p = list(map(int, input().split()))
result = 0
for i in range(2 ** N):
	for (j, v) in enumerate(k):
		s = [1 for temp in v if 2 ** (temp - 1) & i]
		if sum(s) % 2 != p[j]:
			break
	else:
		result += 1
print(result)


import re
import sys
import math
import itertools
import bisect
import heapq
from copy import copy
from collections import deque, Counter
from decimal import Decimal
import functools

def get_primenumber(number):
	prime_list = []
	search_list = list(range(2, number + 1))
	while search_list[0] <= math.sqrt(number):
		head_num = search_list.pop(0)
		prime_list.append(head_num)
		search_list = [num for num in search_list if num % head_num != 0]
	prime_list.extend(search_list)
	return prime_list

def factrization_prime(number):
	factor = {}
	div = 2
	s = math.sqrt(number)
	while div < s:
		div_cnt = 0
		while number % div == 0:
			div_cnt += 1
			number //= div
		if div_cnt != 0:
			factor[div] = div_cnt
		div += 1
	if number > 1:
		factor[number] = 1
	return factor

def v():
	return input()

def k():
	return int(input())

def S():
	return input().split()

def I():
	return map(int, input().split())

def X():
	return list(input())

def L():
	return list(input().split())

def l():
	return list(map(int, input().split()))

def lcm(a, b):
	return a * b // math.gcd(a, b)
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7
cnt = 0
ans = 0
num = []
inf = float('inf')
al = 'abcdefghijklmnopqrstuvwxyz'
AL = al.upper()
(n, m) = I()
switch = [l() for _ in range(m)]
p = l()
for bit in range(2 ** n):
	poi = [0] * n
	for i in range(n):
		if bit >> i & 1:
			poi[i] = 1
	for j in range(m):
		ans = 0
		for k in range(switch[j][0]):
			if poi[switch[j][k + 1] - 1] == 1:
				ans += 1
		if ans % 2 != p[j]:
			break
	else:
		cnt += 1
print(cnt)


import sys

def MI():
	return map(int, sys.stdin.readline().rstrip().split())

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))
(n, m) = MI()
lights = [LI() for _ in range(m)]
p_list = LI()
bit_list = []
count = 0
for i in range(2 ** n):
	bit = [i >> j & 1 for j in range(n)]
	flag = 0
	for j in range(m):
		ki = lights[j][0]
		onswitch = 0
		for k in range(1, ki + 1):
			si = lights[j][k]
			onswitch += bit[si - 1]
		if onswitch % 2 != p_list[j]:
			flag += 1
	if flag == 0:
		count += 1
print(count)


(n, m) = map(int, input().split())
data = []
for i in range(m):
	(k, *s) = map(int, input().split())
	data.append(set(s))
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	on = set()
	for j in range(n):
		if i >> j & 1:
			on.add(j + 1)
	if all([len(on & data[l]) % 2 == p[l] for l in range(m)]):
		ans += 1
print(ans)


(N, M) = map(int, input().split())
KS = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	judge = 1
	for j in range(M):
		cnt = 0
		for k in KS[j][1:]:
			if i >> k - 1 & 1:
				cnt += 1
		if cnt % 2 != p[j]:
			judge = 0
	if judge == 1:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** n):
	flag = True
	for j in range(m):
		if not [1 & i >> k - 1 for k in s[j]].count(1) % 2 == p[j]:
			flag = False
	if flag:
		count += 1
print(count)


(N, M) = map(int, input().split())
L = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	lit = [0] * M
	for (j, switch) in enumerate(L):
		cnt = 0
		for s in switch:
			if i >> s - 1 & 1:
				cnt += 1
		if cnt % 2 == P[j]:
			lit[j] = True
		else:
			lit[j] = False
	if all(lit):
		ans += 1
print(ans)


(N, M) = map(int, input().split())
A = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))
c = 0
for n in range(1 << N):
	for (i, S) in enumerate(A):
		if P[i] ^ sum((n >> s - 1 & 1 for s in S)) & 1:
			break
	else:
		c += 1
print(c)


(N, M) = map(int, input().split())
K = []
S = []
for i in range(M):
	k = 0
	s = []
	(k, *s) = map(int, input().split())
	K.append(k)
	S.append(s)
P = list(map(int, input().split()))
res = 0
for bit in range(1 << N):
	judge = True
	for i in range(M):
		cnt = 0
		for s in S[i]:
			cnt += bit >> s - 1 & 1
		if cnt % 2 != P[i]:
			judge = False
	if judge:
		res += 1
print(res)


(N, M) = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** N):
	bit = [i >> j & 1 for j in range(N)]
	for (k, x) in enumerate(ks):
		(_, *s) = x
		if p[k] != sum([bit[y - 1] for y in s]) % 2:
			break
	else:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	sw = [False] * M
	for j in range(M):
		cnt = 0
		for k in range(1, len(S[j])):
			if i >> S[j][k] - 1 & 1:
				cnt += 1
			else:
				flag = 0
		if cnt % 2 == P[j]:
			sw[j] = True
	if all(sw):
		ans += 1
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ks = list((list(map(int, input().split())) for _ in range(m)))
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	c = [False] * n
	for j in range(n):
		if i >> j & 1:
			c[j] = True
	for j in range(m):
		(count, l) = (0, ks[j][0])
		for k in range(l):
			if c[ks[j][k + 1] - 1]:
				count += 1
		if count % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split()))[1:] for i in range(m)]
p = list(map(int, input().split()))
form = '0' + str(n) + 'b'
ans = 0
for i in range(2 ** n):
	ptr = format(i, form)
	flg = True
	for j in range(m):
		s = sum((int(ptr[k - 1]) for k in l[j]))
		if s % 2 != p[j]:
			flg = False
	if flg == True:
		ans += 1
print(ans)


def func(sw, p, bit):
	sum_on = 0
	for k in range(sw[0]):
		idx = sw[k + 1] - 1
		if bit[idx] == 1:
			sum_on += 1
	if sum_on % 2 == p:
		res = 1
	else:
		res = 0
	return res
(N, M) = list(map(int, input().split()))
SW = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	bit = [0] * N
	for j in range(N):
		div = 1 << j
		bit[j] = i // div % 2
	cnt = 0
	for m in range(M):
		res = func(SW[m], P[m], bit)
		if res == 1:
			cnt += 1
	if cnt == M:
		ans += 1
print(ans)


from itertools import product
(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cnt = 0
for pat in product([0, 1], repeat=n):
	for i in range(m):
		if sum((pat[ks[i][j + 1] - 1] for j in range(ks[i][0]))) % 2 != p[i]:
			break
	else:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
k = [[int(i) for i in input().split(' ')] for i in range(m)]
p = [int(i) for i in input().split(' ')]
c = 0
for i in range(2 ** n):
	t = bin(i + 2 ** n)[2:]
	a = sum([0 if sum([1 if t[l] == '1' else 0 for l in k[j][1:]]) % 2 == p[j] else 1 for j in range(len(k))])
	if a == 0:
		c += 1
print(c)


(n, m) = map(int, input().split(' '))
K = []
S = []
for i in range(m):
	l = list(map(int, input().split(' ')))
	K.append(l[0])
	S.append(l[1:])
p = list(map(int, input().split(' ')))
ans = 0
for i in range(2 ** n):
	light = 0
	for j in range(m):
		sw = 0
		for s in S[j]:
			if i >> s - 1 & 1:
				sw += 1
		if sw % 2 == p[j]:
			light += 1
	if light == m:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
k = [0] * m
s = []
for i in range(m):
	(k[i], *ss) = map(int, input().split())
	s.append(ss)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	bi = bin(i)[2:].zfill(n)
	if all((sum((int(bi[sss - 1]) for sss in ss)) % 2 == p[j] for (j, ss) in enumerate(s))):
		ans += 1
print(ans)


import itertools
(n, m) = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for item in itertools.product([0, 1], repeat=n):
	for i in range(m):
		if sum([item[j - 1] for j in s[i]]) % 2 != p[i]:
			break
	else:
		ans += 1
print(ans)


from sys import stdin

def main():
	lines = stdin.readlines()
	(N, M) = map(int, lines[0].split())
	X = [sum((1 << int(j) - 1 for j in i.split()[1:])) for i in lines[1:-1]]
	Z = lines[-1].split()
	print(sum([1 for i in range(1 << N) if sum([1 for (x, y) in zip(X, Z) if bin(i & x).count('1') % 2 == int(y)]) == M]))
	return
main()


(num_of_switch, light) = list(map(int, input().split()))
ligth_list = [list(map(int, input().split())) for _ in range(light)]
on_list = list(map(int, input().split()))
num_of_patern = 2 ** num_of_switch
patern = 0
for i in range(num_of_patern):
	on = []
	light_counter = 0
	for j in range(num_of_switch):
		if i >> j & 1:
			on.append(j + 1)
	for j in range(light):
		count = 0
		num_connect = ligth_list[j][0]
		if on_list[j] == 1:
			for n in range(len(on)):
				if on[n] in ligth_list[j][1:]:
					count += 1
			if count % 2 == 1:
				light_counter += 1
		else:
			for m in range(len(on)):
				if on[m] in ligth_list[j][1:]:
					count += 1
			if count % 2 == 0:
				light_counter += 1
	if light_counter == light:
		patern += 1
	del on[:]
print(patern)


(N, M) = list(map(int, input().split()))
Switch = [list([int(a) - 1 for a in input().split()])[1:] for i in range(M)]
P = list(map(int, input().split()))
from itertools import product
Target = product([0, 1], repeat=N)
ans = 0
for T in Target:
	akari = []
	for (i, S) in enumerate(Switch):
		temp = 0
		for s in S:
			a = T[s]
			if a == 1:
				temp += 1
		akari.append(temp)
	isOK = True
	for (j, ak) in enumerate(akari):
		if ak % 2 != P[j]:
			isOK = False
	if isOK:
		ans += 1
print(ans)


def resolve():
	(n, m) = map(int, input().split())
	s = list((list(map(int, input().split()))[1:] for _ in range(m)))
	p = list(map(int, input().split()))
	print(sum([1 for i in range(1 << n) if all([sum([1 for sji in sj if i & 1 << sji - 1]) % 2 == pj for (sj, pj) in zip(s, p)])]))
resolve()


import itertools
(N, M) = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
print(sum([all([sum([s[j - 1] for j in v]) % 2 == t for (v, t) in zip(k, p)]) for s in itertools.product([0, 1], repeat=N)]))


(N, M) = list(map(int, input().split()))
li = []
ans = 0
for i in range(M):
	s = list(map(int, input().split()))
	li.append(s)
p = list(map(int, input().split()))
for j in range(2 ** N):
	j = bin(j)
	j = str(j)
	j = j[2:]
	while len(j) != N:
		j = '0' + j
	flash = 0
	for k in range(M):
		temp = 0
		for l in range(li[k][0]):
			if j[li[k][l + 1] - 1] == '1':
				temp += 1
		if temp % 2 == p[k]:
			flash += 1
	if flash == M:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
S = [list(map(int, input().split()))[1:] for i in range(m)]
P = list(map(int, input().split()))
cnt = 0
for i in range(2 ** n):
	pattern = format(i, 'b').zfill(n)
	point = 0
	for j in range(m):
		swi = 0
		for k in S[j]:
			if pattern[k - 1] == '1':
				swi += 1
		if swi % 2 == P[j]:
			point += 1
	if point == m:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	bnt = 0
	for j in range(m):
		cnt = 0
		for l in range(1, len(ks[j])):
			if i >> ks[j][l] - 1 & 1 == 1:
				cnt += 1
		if cnt % 2 == p[j]:
			bnt += 1
	if bnt == m:
		ans += 1
print(ans)


def abc128c_switches():
	import itertools
	(n, m) = map(int, input().split())
	s = []
	for _ in range(m):
		v = list(map(int, input().split()))
		v = v[1:]
		s.append(v)
	p = list(map(int, input().split()))
	pattern = itertools.product([0, 1], repeat=n)
	result = 0
	for pat in pattern:
		cnt = 0
		for i in range(m):
			total = 0
			for j in s[i]:
				if pat[j - 1] == 1:
					total += 1
			if total % 2 == p[i]:
				cnt += 1
		if cnt == m:
			result += 1
	print(result)
abc128c_switches()


(n, m) = map(int, input().split())
s = [[x for x in map(int, input().split())] for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
	c = 1
	for j in range(m):
		t = 0
		for k in range(1, s[j][0] + 1):
			if i >> s[j][k] - 1 & 1 == 1:
				t += 1
		if t % 2 != p[j]:
			c = 0
			break
	if c:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
s = [[0] * 10 for _ in range(m)]
for i in range(m):
	k = list(map(int, input().split()))
	for j in range(1, k[0] + 1):
		s[i][10 - k[j]] = 1
import numpy as np
s = np.asarray(s)
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
	binst = format(i, '010b')
	l = list(map(int, list(binst)))
	l = np.asarray(l)
	on = s & l
	onsum = np.sum(on, axis=1) % 2
	err = 0
	for j in range(m):
		if onsum[j] != p[j]:
			err = 1
			break
	if err == 0:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [list(map(int, input().split()[1:])) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for b in range(1 << n):
	if all((sum((b >> i - 1 & 1 for i in s[j])) % 2 == p[j] for j in range(m))):
		ret += 1
print(ret)


(N, M) = map(int, input().split())
lights = [list(map(lambda x: int(x) - 1, input().split()))[1:] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	for m in range(M):
		on_sum = 0
		for j in range(N):
			if i >> j & 1 and j in lights[m]:
				on_sum += 1
		if on_sum % 2 != p[m]:
			break
	else:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
s = [0] * m
for i in range(m):
	s[i] = list(map(int, input().split()))
	del s[i][0]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** n):
	for k in range(m):
		temp = 0
		for j in range(n):
			if i >> j & 1 and j + 1 in s[k]:
				temp = temp + 1
		if temp % 2 != p[k]:
			break
	else:
		count = count + 1
print(count)


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(m)]
k2 = []
for v in k:
	a = [2 ** (v[i] - 1) for i in range(1, v[0] + 1)]
	k2.append(sum(a))
p = list(map(int, input().split()))
sm = 0
for i in range(2 ** n):
	c = 1
	for j in range(m):
		b = bin(k2[j] & i)
		d = b.count('1')
		if d % 2 != p[j]:
			c = 0
	if c == 1:
		sm += 1
print(sm)


(n, m) = map(int, input().split())
ans = 0
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
for i in range(1 << n):
	for j in range(m):
		c = 0
		for ss in s[j][1:]:
			if i & 1 << ss - 1:
				c += 1
		if c % 2 != p[j]:
			break
	else:
		ans += 1
print(ans)


3
(N, M) = (int(x) for x in input().split())
S = []
for i in range(M):
	items = [int(x) - 1 for x in input().split()]
	S.append(items[1:])
P = [int(x) for x in input().split()]
ret = 0
for bit in range(2 ** N):
	on = [i for i in range(N) if bit & 1 << i]
	ok = True
	for i in range(M):
		s = S[i]
		p = P[i]
		if sum((1 for switch in s if switch in on)) % 2 != p:
			ok = False
			break
	if ok:
		ret += 1
print(ret)


(N, M) = map(int, input().split())
KS = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(1 << N):
	tmp = 1
	for (j, b) in enumerate(KS):
		if sum([1 for bb in b[1:] if i >> bb - 1 & 1 == 1]) % 2 != P[j]:
			tmp = 0
			break
	if tmp:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))

def get_connected_switches():
	lst = list(map(int, input().split()))
	lst.pop(0)
	return list([1 << d - 1 for d in lst])
cs = [get_connected_switches() for _ in range(m)]
ps = list(map(int, input().split()))
ans = 0
for on in range(2 ** n):
	ok = True
	for i in range(m):
		ct = 0
		for s in cs[i]:
			if s & on:
				ct += 1
		if ct % 2 != ps[i]:
			ok = False
	if ok:
		ans += 1
print(ans)


from itertools import product
(n, m) = map(int, input().split())
sp = [list(map(int, input().split())) for _ in range(m + 1)]
print(sum((all((sum((i[a - 1] for a in s[1:])) % 2 == p for (s, p) in zip(sp[:m], sp[-1]))) for i in product((0, 1), repeat=n))))