Problem:
 Score : 300 points    Problem Statement 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 1 2 2
2 1 2
1 2
0 1      Sample Output 1 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 .       Sample Input 2 2 3
2 1 2
1 1
1 2
0 0 1      Sample Output 2 0   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 even number of switches that are "on" among the following: Switch 1 .  Bulb 3 is lighted when there is an odd number of switches that are "on" among the following: Switch 2 .   Switch 1 has to be "off" to light Bulb 2 and Switch 2 has to be "on" to light Bulb 3 , but then Bulb 1 will not be lighted. Thus, there are no combinations of states of the switches that light all the bulbs, so we should print 0 .       Sample Input 3 5 2
3 1 2 5
2 2 3
1 0      Sample Output 3 8

Solution (Python):
import sys

n, m = list(map(int, input().split()))
swi = []
for _ in range(m):
    k, *sss = list(map(int, input().split()))
    t = 0
    for s in sss:
        t += 1 << (s - 1)
    swi.append(t)
ppp = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    for s, p in zip(swi, ppp):
        t = i & s
        c = bin(t).count('1') % 2
        if c != p:
            break
    else:
        ans += 1
print(ans)

Solution (Python):
idx = lambda x: x-1
n, m = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    b = bin(i)[2:].rjust(n, "0")
    light = True
    for i, di in enumerate(d):
        sw = 0
        for j in di[1:]:
            sw += int(b[idx(j)])
        if sw % 2 != p[i]:
            light = False
            break
    if light:
        ans += 1
print(ans)

Solution (Python):
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 r in range(M):
        on_sum = 0
        for j in range(N):
            if (i >> j)&1 and j in lamps[r]:
                on_sum += 1
        if on_sum % 2 != p[r]:
            break
    else:
        ans += 1
        
print(ans)

Solution (Python):
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect




from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, m = map(int, readline().split())
  sw = [[] for _ in range(m)]
  for i in range(m):
    sw[i] = list(map(int, readline().split()[1:]))
  p = [int(x) for x in input().split()] 
  answer = 0
  
  for jotai in product([0,1], repeat=n):
    bl = True
    for i in range(m):
      s = sum([jotai[s-1] for s in sw[i]])
      if (s-p[i])%2 != 0:
        bl = False
        break
    if bl:
      answer += 1
  print(answer)
  
  
  
if __name__ == '__main__':
  main()

Solution (Python):
def solve():
    N, M = map(int, input().split())
    k = []
    s = []
    for i in range(M):
        tmp = list(map(int, input().split()))
        tmpk = tmp[0]
        tmps = list(map(lambda x:x-1,tmp[1:]))
        k.append(tmpk)
        s.append(tmps)
    
    p = list(map(int, input().split()))

    ans = 0
    for bit in range(1 << N):
        on_switches = set() 
        for j in range(N):
            if (1 << j) & bit:
                on_switches.add(j)
        
        for i in range(M):
            cnt = 0
            for j in range(k[i]):
                if s[i][j] in on_switches:
                    cnt += 1
            
            if cnt % 2 != p[i]:
                break
        else:
            ans += 1
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
n,m = map(int, input().split())
switch = [list(map(int, input().split())) 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):
        on = 0
        for k in switch[j][1:]:
            if (i>>k-1)&1:
                on +=1
        if on%2 != p[j]:
            flag = False
    if flag:
        count +=1
print(count)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

def main():
    N, M = input_nums()
    lights = {}
    for i in range(M):
        s = input_nums()[1:]
        lights[i] = s
    p = input_nums()
    cnt = 0
    for bit in range(1<<N):
        on = True
        
        for l in range(M):
            ll = lights[l]
            cnt_each = 0
            
            for i in range(N):
                if bit & (1<<i):
                    
                    if not (i+1) in ll:
                        continue
                    cnt_each += 1
            if cnt_each%2 == p[l]:
                continue
            else:
                on = False
                break
        if on:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):


import sys













def main():
    mod = 10000007                  
    inf = float('inf')
    input = sys.stdin.readline      
    sys.setrecursionlimit(10**6)    
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    

    def illuminate_p(state, bulb, L, P):
        connected_count = 0
        mask = 0b1
        for switch in L[bulb]:
            if state & (mask << switch):
                connected_count += 1
        return connected_count % 2 == P[bulb]
    

    n, m = mi()
    L = [None] * m
    
    for i in range(m):
        line = list(map(lambda x: int(x)-1, input().rstrip().split()))
        L[i] = line[1:]
    P = lmi()

    ans = 0
    
    for state in range(2**n):
        for bulb in range(m):
            if not illuminate_p(state, bulb, L, P):
                break
        else:
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
N,M = map(int,input().split())
k = [list(map(int,input().split()))[1:] for _ in range(M)]
p = list(map(int,input().split()))
cnt = 0
for i in range(2**N):
    switch = bin(i)[2:].zfill(N)
    flag = True
    for j in range(M):
        on = 0
        for index in k[j]:
            if switch[index-1] == '1':
                on += 1
        if on % 2 != p[j]:
            flag = False
            break
    if flag:
        cnt += 1
print(cnt)

Solution (Python):
N, M = map(int, input().split())
K = [[] for i in range(M)]
for i in range(M):
    k = list(map(int, input().split()))
    K[i] = k[1:]
 
P = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
    switch = [0] * M
    for j in range(N):
        if (i >> j) & 1: 
            for l in range(M):
                if j + 1 in K[l]: 
                    switch[l] += 1 
     
    for j in range(M):
        if switch[j] % 2 != P[j]:
            break 
    else:
        ans += 1
        
print(ans)

Solution (Python):
N, M = map(int, input().split())


K = [[0]*N for i in range(M)]


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


print(ans)

Solution (Python):

"""
Created on Fri Apr  3 14:23:44 2020

@author: liang
"""

N, M = map(int,input().split())
bulbs = [list(map(int,input().split()))[1:] for _ in range(M)]
p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    lights = [1 if (i>>j)&1 == 1 else 0 for j in range(N)]
    if all(sum(lights[x-1] for x in bulbs[k])%2 == p[k] for k in range(len(bulbs))):
            ans += 1


print(ans)

Solution (Python):
n, m = map(int, input().split())
s = [[] for i in range(m)]
for i in range(m):
    s[i] = list(map(int, input().split()))[1:]
p = list(map(int, input().split()))
count = 0
for i in range(2**n):
    light = bin(i)[2:].zfill(n)
    flag = True
    for j in range(m):
        work = 0
        for el in s[j]:
            if light[el-1] == '1':
                work += 1
        if work%2 != p[j]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Solution (Python):

n, m = map(int, input().split())
k =[0]*m
s = [0]*m
for i in range(m):
    lst=input().split()
    k[i] = int(lst[0])
    s[i] = [int(x) - 1 for x in lst[1:]]
p = [int(x) for x in input().split()]

ans=0
for i in range(2 ** n):
    all_on = True
    for j in range(m):
        light = 0
        for k in s[j]:
            tmp = i >> k & 1
            
            
            light = (light + tmp) % 2
            
        if light != p[j]:
            all_on = False
            
            break
    ans += int(all_on)
print(ans)

Solution (Python):
N, M = map(int, input().split())

X = []
for _ in range(M):
    t = list(map(int, input().split()))
    X.append(t[1:])

P = list(map(int, input().split()))

r = 0
for i in range(2**N):
    j = i
    c = 1
    cs = set()
    while j:
        if j % 2:
            cs.add(c)
        j //= 2
        c += 1

    for i in range(M):
        t = 0
        for x in X[i]:
            if x in cs:
                t += 1
        if t%2 != P[i]:
            break
    else:
        r += 1

print(r)

Solution (Python):
n, m = map(int, input().split())
s = [[] for i in range(m)]
for i in range(m):
    s[i] = list(map(int, input().split()))[1:]
p = list(map(int, input().split()))
count = 0
for i in range(2**n):
    light = bin(i)[2:].zfill(n)
    flag = True
    for j in range(m):
        work = 0
        for el in s[j]:
            if light[el-1] == '1':
                work += 1
        if work%2 != p[j]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Solution (Python):
from collections import deque

N, M = [int(x) for x in input().split()]
k = [None] * M
s = [None] * M
for i in range(M):
    lst = input().split()
    k[i] = int(lst[0])
    s[i] = [int(x) - 1 for x in lst[1:]]  
p = [int(x) for x in input().split()]

ans = 0

for sw in range(2 ** N):
    all_on = True
    for i in range(M):  
        light = 0
        for j in s[i]:  
            light = (light + (sw >> j) & 1 ) % 2
        if light != p[i]:
            all_on = False
            break
    ans += int(all_on)
print(ans)

Solution (Python):
n,m=map(int,input().split())
K=[]
S=[]
for i in range(m):
    x=list(map(int,input().split()))
    K.append(x[0])
    S.append(list(x[1:]))
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    flg=True
    for j in range(m):
        tmp=0
        for k in S[j]:
            if i>>(k-1) & 1:
                tmp+=1
        if tmp%2==p[j]:
            continue
        else:
            flg=False
    if flg:
        ans+=1

print(ans)

Solution (Python):
N, M = map(int, input().split())
S = []
for _ in range(M):
    ipt = [int(i) for i in input().split()]
    S.append([True if i in ipt[1:] else False for i in range(1, N+1)])
P = [int(p) for p in input().split()]

ans = 0
for cmb in range(0, 2**N):
    b = list(str(bin(cmb)))[2:]
    cmb_b = ["0"]*(N-len(b)) + b
    cur_cnd = [0]*M
    for s_cnd, i in zip(reversed(cmb_b), range(N)):
        for s, j in zip(S, range(M)):
            if s_cnd == "1" and s[i]:
                cur_cnd[j] = (cur_cnd[j]+1) % 2
    if P == cur_cnd:
        ans += 1

print(ans)

Solution (Python):
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)]))

Solution (Python):
N,M=map(int,input().split())
K=[]
S=[]
ans=0
for i in range(M):
    tmp=list(map(int,input().split()))
    k,s=tmp[0],tmp[1:]
    K.append(k)
    S.append(s)
p=list(map(int,input().split()))
for s in range(2**N):
    cnt=[0]*M
    f=1
    for i in range(M):
        k=S[i]
        for j in k:
            if (s>>(j-1)&1):
                cnt[i]+=1
        if cnt[i]%2!=p[i]:
            f=0
            break
    if f==1:
        ans+=1
print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ks = nan(m)
p = na()

ans = 0
for i in range(2 ** n):
    ok = True
    for j in range(m):
        k, s = ks[j][0], ks[j][1:]
        sum_on = 0
        for a in range(k):
            if (i >> (s[a] - 1)) & 1:
                sum_on += 1
        if sum_on % 2 != p[j]:
            ok = False
    if ok:
        ans += 1

print(ans)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n, m = na()
ks = nan(m)
p = na()

ans = 0
for i in range(2 ** n):
    on = dict()
    for j in range(n):
        if (i >> j) & 1:
            on[j + 1] = True
    l = 0
    for j in range(m):
        k, s = ks[j][0], ks[j][1:]
        sum_on = 0
        for a in range(k):
            if on.get(s[a], False):
                sum_on += 1
        if sum_on % 2 == p[j]:
            l += 1
    if l == m:
        ans += 1

print(ans)

Solution (Python):
N, M = map(int, input().split())


K = [[0]*N for i in range(M)]


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


print(ans)

Solution (Python):
n, m = map( int, input().split())

l = [[0] * n for _ in range( m )]
for i in range( m ):
  k = list( map( int, input().split() ))
  for j in range( 1, k[0] + 1 ):
    l[i][ k[ j ] - 1] = 1
p = list( map( int, input().split() ) )

ret = 0
for i in range( 2 ** n ):
  b = [ int(k) for k in str( format(i,'b').zfill(n))]
  cnt = 0
  for j in range( m ): 
    a = 0
    for k in range( n ):
      a += b[ k ] * l[ j ][ k ]
    if a % 2 == p[ j ]:
      cnt += 1
  if cnt == m:
    ret += 1
print( ret )

Solution (Python):
import numpy as np
from itertools import product

def main():
    n, m = [int(i) for i in input().split()]
    sw = np.zeros((m, n), int)
    for i in range(m):
        for s in input().split()[1:]:
            sw[i][int(s)-1] = 1

    p = np.array([int(i) for i in input().split()])
    res = 0
    for t in product((0, 1), repeat=n):
        stat = np.array(t)
        if np.array_equal(p, np.dot(sw, stat) % 2):
            res += 1
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())

s = []
for _ in range(m):
    s.append(list(map(int,input().split())))

p = list(map(int,input().split()))

l = []
ans = 0
for i in range(2**n):
    l = []
    for j in range(n):
            if i & (1<<j):
                l.append(j+1)

    flag = True
    for j in range(m):
        kosu = 0
        for k in l:
            if k in s[j][1:]:
                kosu += 1
        if kosu % 2 != p[j]:
            flag = False
            break

    if flag:
        ans += 1


print(ans)

Solution (Python):
n, m = map(int, input().split())
q = []
s = []
for i in range(m):
    x = [int(i) for i in input().split()]
    q.append(x[0])
    s.append(x[1:])
p = list(map(int, input().split()))
ans = 0


for i in range(2**n):
    ok = True
    for j in range(m):
        on_cnt = 0
        for k in range(q[j]):
            for l in range(n):
                if i >> l & 1:
                    if l == s[j][k] - 1:
                        on_cnt += 1
        if on_cnt % 2 != p[j]:
            ok = False
    if ok:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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 bit in range(1 << N):
    for i in range(M):
        cnt = 0
        for s in S[i]:
            if bit >> (s-1) & 1:
                cnt += 1
        if cnt % 2 != p[i]:
            break
    else:
        ans += 1
print(ans)

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

Solution (Python):

def dfs(cnt):
    global ans
    if cnt == N:
        onF = True
        for i in range(M):
            tmp = 0
            for j in range(ks[i][0]):
                if bit[ks[i][j + 1] - 1] == 1:
                    tmp += 1
            if tmp % 2 != p[i]:
                onF = False
                break
        if onF:
            ans += 1
        return
    for i in range(2):
        bit[cnt] = i
        dfs(cnt + 1)


N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
bit = [0] * N
ans = 0
dfs(0)
print(ans)

Solution (Python):
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):
  q=[0]*n
  for j in range(n):
    if i>>j&1:
      q[j]=1
  for j in range(m):
    cnt=0
    for k in ks[j][1:]:
      if q[k-1]==1:
        cnt+=1
    if cnt%2!=p[j]%2:
      break
  else:
    ans+=1
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
s = [inpl() for i in range(m)]
p = inpl()
res = 0
for flag in itertools.product([0,1], repeat=n):
    on = set()
    for i,j in enumerate(flag):
        if j: on.add(i+1)
    ok = True
    for i,j in enumerate(s):
        cnt = 0
        for k,l in enumerate(j):
            if k == 0: continue
            if l in on: cnt += 1
        if cnt%2 != p[i]:
            ok = False
            break
    if ok: res += 1
print(res)

Solution (Python):
def main():
    N, M = (int(i) for i in input().split())
    S = []
    for _ in range(M):
        k, *s = (int(i)-1 for i in input().split())
        S.append(set(s))
    P = [int(i) for i in input().split()]
    ans = 0
    for bit in range(1 << N):
        on = set()
        for i in range(N):
            if bit & (1 << i):
                on.add(i)
        if all(len(S[i] & on) % 2 == P[i] for i in range(M)):
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    s = []
    for i in range(m):
        a = LI()[1:]
        for j in range(len(a)):
            a[j] -= 1
        s.append(a)
    p = LI()
    ans = 0
    for b in range(1<<n):
        su = [0]*m
        for i in range(m):
            for j in s[i]:
                if b&(1<<j):
                    su[i] ^= 1
        if su == p:
            ans += 1
    print(ans)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
N,M = map(int,input().split()) 
light=[]
for i in range(M):
    light.append(list(map(int,input().split())))



p = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    
    sw = [0]*N
    for j in range(N):
        if ((i >>j) & True):
            sw[j]=1
    On_Light_nmb = 0
    for m in range(M): 
        sum = 0
        for k in range(light[m][0]):
            s_nmb = int(light[m][k+1])
            sum += sw[s_nmb-1]

        if sum%2 == p[m]: 
            
            On_Light_nmb +=1


    
    if On_Light_nmb == m+1:
        ans +=1

print(ans)

Solution (Python):
N, M = map(int, input().split())
lamps = [list(map(int, input().split()))[1:] for _ in range(M)]
Ps = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    clear = True
    for idx, l in enumerate(lamps):
        on = 0
        for j in range(N):
            if ((i>>j) &1):
                if j+1 in l:
                    on += 1
        if not on%2==Ps[idx]:
            clear = False
            break
    if clear:
        ans += 1
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))





def main():
	n,m=MI()
	ks=[LI() for _ in range(m)]
	s=[i[1:] for i in ks]
	p=LI()
	ans=0

	for i in range(1<<n):
		li=[0]*m
		for j in range(n):
			for k in range(m):
				if 1&i>>j:
					if j+1 in s[k]:
						li[k]=1-li[k]
		if p==li:
			ans+=1
	print(ans)










if __name__ == "__main__":
	main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    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):
        
        flg = True
        for j in range(M):
            
            c = 0
            for k in range(ks[j][0]):
                if (i>>(ks[j][k+1]-1))&1:
                    c += 1
            if c%2!=p[j]:
                flg = False
        if flg:
            ans += 1
    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n,m=map(int,input().split())
K=[]
for i in range(m):
    _,*a=map(int,input().split())
    K.append(a)
P=list(map(int,input().split()))

ans=0
for i in range(2**n):
    S=[]
    flag=0
    for j in range(n):
        S.append(i>>j)
    for j in range(m):
        lamp=K[j]
        cnt=0
        for k in lamp:
            cnt+=S[k-1]
        if cnt%2!=P[j]:
            flag=1
            break
    if flag==0:
        ans+=1
print(ans)

Solution (Python):

n, m = map(int, input().split())
k = [0] * (m+1)
s = [[] for _ in range(m+1)] 
for i in range(1, m+1):
    tmp = list(map(int, input().split()))
    k[i] = tmp[0]
    s[i] = tmp[1:]

p = list(map(int, input().split()))


seq = [0, 1]
import itertools
arr = itertools.product(seq, repeat=n)





ans = 0
for v in arr:
    v = [0] + list(v)
    flag = True
    
    for light in range(1,m+1):
        t = s[light]
        count = 0
        for i in range(len(t)):
            count += v[t[i]]
        if count % 2 != p[light-1]:
            flag = False
    if flag:
        ans += 1


print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
from itertools import combinations

def readlines(n):
    for _ in range(n):
        k, *s = map(int, input().split())
        yield s

def on(s, p, comb):
    return len([s_ for s_ in s if s_ in comb]) % 2 == p

def main():
    n, m = map(int, input().split())
    switches = list(range(1, n+1))
    S = list(readlines(m))
    P = list(map(int, input().split()))
    for i in range(n+1):
        for comb in combinations(switches, i):
            if all(on(s, p, set(comb)) for s, p in zip(S, P)):
                yield 1

print(sum(main()))

Solution (Python):
N,M = map(int,input().split())
Lamp = [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):
    judge = True
    for l in range(M): 
        cnt = 0
        for j in range(N):
            if (i >> j) & 1 and (j in Lamp[l]):
            
                cnt += 1
        if cnt % 2 != p[l]:
            judge = False
            break
    if judge:
        ans += 1

print(ans)

Solution (Python):
N,M=list(map(int,input().split()))
kslst=[list(map(int,input().split())) for _ in range(M)]
p=list(map(int,input().split()))

mbit=[0]*M
allon=2**M-1

ret=0

for i,ks in enumerate(kslst):
    k=ks[0]
    for j in range(1,k+1):
        mbit[i]+=2**(ks[j]-1)

for i in range(2**N):
    cstate=0
    for j in range(M):
        cnt=0
        for k in range(N):
            if (i>>k)&1==1 and (mbit[j]>>k)&1==1:
                cnt+=1
        
        cstate+=2**j if cnt%2==p[j] else 0
    
    if cstate&allon==allon:
        ret+=1

print(ret)

Solution (Python):
from collections import deque

N, M = [int(x) for x in input().split()]
k = [None] * M
s = [None] * M
for i in range(M):
    lst = input().split()
    k[i] = int(lst[0])
    s[i] = [int(x) - 1 for x in lst[1:]]  
p = [int(x) for x in input().split()]


que = deque([[]]) 
ans = 0
while len(que) > 0:
    sw = que.popleft()  
    if len(sw) >= N:
        all_on = True
        for i in range(M):  
            light = 0
            for j in s[i]:  
                light = (light + sw[j]) % 2
            if light != p[i]:
                all_on = False
                break
        ans += int(all_on)
    else:
        que.append(sw + [0])
        que.append(sw + [1])

print(ans)

Solution (Python):
n, m = map(int,input().split())
light = [list(map(int,input().split())) for _ in range(m)]
check = list(map(int,input().split()))
ans = 0

for i in range(2 ** n):
    swicth = [0] * n
    
    for j in range(n):
        if ((i >> j) & 1):
            swicth[n - 1 -j] = 1
            
    check_cnt = 0        
    for k in range(m):
        a = light[k][0]
        swicth_on_cnt = 0
        for b in range(a):
            swicth_number = light[k][1+b]
            if swicth[swicth_number - 1] == 1:
                swicth_on_cnt += 1
        if swicth_on_cnt%2 == check[k]:
            check_cnt += 1

    if check_cnt == m:
        ans += 1

print(ans)

Solution (Python):
N,M=map(int,input().split())
lamp=[list(map(int,input().split())) for _ in range(M)]
restrict=list(map(int,input().split()))
l=[0]*N
cnt=0
flag=0
ans=0
for i in range(pow(2,N)):
    for j in range(N):
        l[j]=(i>>j)&1
    for j in range(M):
        for k in range(len(lamp[j])-1):
            cnt=cnt+l[lamp[j][k+1]-1]
        if (cnt%2)==restrict[j]:
            flag=flag+1
        cnt=0
    if flag==M:
        ans=ans+1
    flag=0
print(ans)

Solution (Python):
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()))
ans=0

for z in product((0, 1), repeat=n):
    for i in range(m):    
        k=ks[i][0]
        on_count=0
        for j in range(1,k+1):
            if z[ks[i][j]-1]==1:
                on_count+=1
        if  on_count%2!=p[i]:
            break
    else:
        ans+=1
print(ans)

Solution (Python):





def calc_dis(A,B,li,N):
    dis = 0
    for i in range(N):
        dis += abs(A-li[i][0]) + abs(li[i][0]-li[i][1]) + abs(B-li[i][1])
    return dis

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

    ans = 0
    for i in range(1<<(N)):
        li = [0 for i in range(M)]
        for j in range(N):
            if (i>>j)&1: 
                for k in range(M):
                    if (j+1) in S[k]:
                        li[k] += 1
        
        for j in range(M):
            if li[j]%2!=P[j]:
                break
        else:
            
            ans += 1
        

    print(ans)



    

main()

Solution (Python):
N, M = map(int, input().split())

lights = list()
for i in range(M):
   swithes = list(map(int, input().split()))
   lights.append(swithes[1:])

light_on_condition = list(map(int, input().split()))

ans = 0
for mask in range(1<<N):
    swithes_status = [0] * M
    for i in range(N):
        if mask & (1<<i) >= 1:
            
            for j, light in enumerate(lights):
                if (i+1) in light:
                    swithes_status[j] += 1
    full_on = True
    for condition, status in zip(light_on_condition, swithes_status):
        if condition != status % 2:
            full_on = False
            break
    if full_on:
        ans += 1

print(ans)