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



Sample input:
2 2
2 1 2
1 2
0 1


Sample output:
1

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(1<<n):             # 全switch(n)のon/offパターン数
    sw = [False]*m                # 各電球の点灯リストを作成
    for j in range(m):            # 各電球について
        cnt = 0
        for k in range(1,len(s[j])):   # 各電球のswitchについて
            if i>>s[j][k]&1:
                cnt += 1
        if cnt%2==p[j]:
            sw[j]=True
    if all(sw):
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
s = list(list(map(int, input().split())) for _ in range(m)) 
p = list(map(int,input().split()))
ans = 0
for i in range(1<<n):
    # 全switch(n)のon/offパターン数
    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

        if cnt%2==p[j]:
            sw[j]=True
    if all(sw):
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
s = list(list(map(int, input().split())) for _ in range(M)) 
p = list(map(int,input().split()))
ans = 0
for i in range(1<<n):
    # 全switch(n)のon/offパターン数
    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
        if cnt%2==p[j]:
            sw[j]=True
    if all(sw):
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
ans = 0
for i in range(1<<n):
    # 全switch(n)のon/offパターン数
    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
        if cnt%2==p[j]:
            sw[j]=True
    if all(sw):
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = []
for _ in range(M):
    A.append(tuple(map(int, input().split())))
P = tuple(map(int, input().split()))
import itertools
def hantei(A, RETU, P):
    for i in range(len(A)):
        count = 0
        for k in RETU:
            if k in A[i][1:]:
                count += 1
        if not count % 2 == P[i]:
            return False
    return True
ans = 0
for i in range(1, N + 1):
    for k in itertools.combinations(range(1, N + 1), i):
        if hantei(A, k, P):
            ans += 1
if hantei(A, 0, P):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*m
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*8
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
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 ksi, pi in zip(ks, pi):
        tmp = sum(pat[ksij - 1] for ksij in ksi[1:])
        if  tmp % 2 != pi:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
state = []
for _ in range(M):
  lst = list(map(int, input().split()))
  state.append(lst[1:])#switch numbers each denkyu
p = list(map(int, input().split()))#numbers switches on %2 == pi 
ans = 0
for i in rage(2**n):
  total = 0
  for j in range(m):
    cnt = 0
    for s in state[j]:
      s -= 1
      if (i >> s) & 1:#全スイッチのパターン一つ一つについて、各電球の各スイッチがオンになっているか
        cnt += 1
    cnt %= 2
    if cnt == p[j]:
      total += 1
  if total == m:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
n, m = map(int, input().split())
denq = []
for _ in range(m):
    ks = tuple(map(lambda x: int(x)-1, input().split()))
    denq.append(ks[1:])
P = tuple(map(int, input().split()))

ans = 0
for i in range(2**n):
    kk = [0] * m
    # switch_states = [(i>>j)&1 for j in range(n)]
    for idq, dq in enumerate(denq):
        counts = 0
        for s in dq:
            counts += (i>>s)&1
        if counts%2 != P[idq]:
            break
    else:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
"""
ビット全探索
"""
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()))

#ビット全探索
for i in range(2**n) :
    for r in range(m) :
        on = 0
        for j in range(n) :
            #j桁目が1であるかどうかを調べる
            #jがsに含まれているかどうか調べる
            if (i>>j) & 1 == 1 and j in lamps[r] :
                on += 1
        if on % 2 != p[r] :
            break
    else :
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

lamps = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(n)]
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)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

lamps = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(n)]
p = 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)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
q = [list(map(int, input().split())) for i in range(m)]
ans = 0

for s in range(2**n): #スイッチのon/offの状態の総当たり（2**n通り）
    judge = True
    for i in range(m): #電球1つずつに対して
        cnt=0
        for j in range(1,len(q[i])): #sの総当たりでqに当てはまるものを探す。kはforを1からにすれば無視できる。
            w=q[i][j]
            if s >> (w-1) &1 ==1: #sをw-1回シフトさせて(w-1)個目のスイッチがonか判定
                cnt+=1 #onになっているスイッチの個数をカウント
        if cnt % 2 != p[i]: #スイッチの個数を2で割った余りがpiに等しいか判定
            judge = False
    if judge:
        ans += 1

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, len(q[i]):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
q = list()
for i in range(m):
    q.append(list(map(int, input().split())))
p = list(map(int, input().split()))

ans = 0

for s in range(2**n):
    judge = True
    for i in range(m):
        cnt = 0
        for j in range(1, q[i][0]):
            w = q[i][j]
            if s >>(w-1) & 1 == 1:
                cnt += 1
        if cnt % 2 != p[i]:
            judge = False
    if judge:
        res += 1
print(res)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
denkyu_switch=[]
res=0
for i in range(m):
    denkyu_switch+=[list(map(int, input().split()))[1:]]
p=list(map(int, input().split()))
for i in range(2**n):
    denkyu = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in denkyu_switch:
                if j in k:
                    denkyu[k]+=1
    if p==denkyu:
        res+=1
print(res)

Submission status: Runtime Error

Solution code:
from itertools import product
N,M = map(int,input().split())
cc = []
for i in range(M):
  ll = list(map(int,input().split()))
  cc.append(ll)
p = list(map(int,input().split()))
count = 0
for i in product('01',repeat = N):
  on = 0
  bulb = 0
  for j in range(M):
    for k in range(cc[j][0]):
      if i[cc[m][l+1]-1] == 1:
        on += 1
    if on % 2 == p[j]:
      bulb += 1
  if bulb == M:
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
N,M = map(int,input())
K = []
S = []
for i in range(M):
    list = input().split()
    K.append(int(list[0]))
    S.append(map(int,list[1::]))
p = list(map(int,input().split()))
anss = 0
for i in range(2**n):
    for j in range(M):
        ans = 0
        for k in range(N):
            if i >> k & 1 and k in K[j]:
                ans += 1
        if ans % 2 != p[j]:
            break
        else:
            anss += 1
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
n, m = map(int, input().split())
switch = []
for _ in range(m):
    k, *s = map(lambda x: int(x)-1, input().split())
    switch.append(s)
p = map(int, input().split())

ans = 0
for subset in product((0, 1), n):
    for j in range(m):
        on_cnt = sum(subset[s] for s in switch[j])
        if on_cnt % 2 != p[j]:
            break
    else:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
 
N, M = map(int, input().split())
lights = []
for m in range(M):
  
  interpools mpzp(input())
    tmp = list(map(int, input().split()))
    lights.append(tmp[1:])
 
 
P = list(map(int, input().split()))
 
ans = 0
for product in list(itertools.product([0, 1], repeat=N)):
    for light in range(len(lights)):
        cnt = 0
        for l in lights[light]:
            cnt += product[l-1]
        if cnt % 2 != P[light]:
            break
        if light == len(lights) - 1:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
 
N, M = map(int, input().split())
lights = []
for m in range(M):
  
  interpools mpzp(int,Input().spli
    tmp = list(map(int, input().split()))
    lights.append(tmp[1:])
 
 
P = list(map(int, input().split()))
 
ans = 0
for product in list(itertools.product([0, 1], repeat=N)):
    for light in range(len(lights)):
        cnt = 0
        for l in lights[light]:
            cnt += product[l-1]
        if cnt % 2 != P[light]:
            break
        if light == len(lights) - 1:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ks=[]
for _ in range(m):
  ks.append(list(map(int,input().split())))
p=list(map(int,input().split()))
  

counter=0
for i in range(2**n): #iはbit
  all_are_lighting=1
  for j in range(m): #電球をそれぞれ考える
    switch_on=0 #有効なスイッチがオンの数を記録
    print(m)
    for k_and_ss in ks[m]:#m番目の電球につながっているスイッチのリスト
      num_of_switch=k_and_ss[0]
      for s in k_and_ss[1:]:#onであるスイッチの数を記録
        if (i >> s) & 1:
          switch_on+=1
        if switch_on%2!=p[j]:
          all_are_lighting*=0
          break
    if all_are_lighting==1:
      counter+=1
  
  print(bin(i))
  print(len(bin(i)))

Submission status: Runtime Error

Solution code:
n,m = list(map(int,input().split()))
l_list = [list(map(int,input().split())) for i in range(m)] 
p = list(map(int,input().split()))
output = 0

for i in range(2 ** n):
  lights = []
  for j in range(n+1):
    if ((i >> j) & 1):
      lights.append(j+1)
      
  for l in l_list:
    if len(set(l[1:]) & set(lights)) % 2 != p[l[0]-1] or len(set(l[1:]) & set(lights)) ==0:
      break
  else:
    output += 1
print(output)

Submission status: Runtime Error

Solution code:
n,m = list(map(int,input().split()))
l_list = [list(map(int,input().split())) for i in range(m)] 
p = list(map(int,input().split()))
output = 0

for i in range(2 ** n):
  lights = []
  for j in range(n+1):
    if ((i >> j) & 1):
      lights.append(j+1)
      
  for l in l_list:
    if len(set(l[1:]) & set(lights)) % 2 != p[l[0]-1]:
      break
  else:
    output += 1
print(output)

Submission status: Runtime Error

Solution code:
ans = 0
for bit in range(1<<N):
    count = [0]*M
    for i in range(N):
        if (bit >> i) & 1:
            for a in range(M):
                if i in ks[a][1:]:
                    count[a] +=1
    a = 0
    for i in range(M):
        if count[i] % 2 == p[i]:
            a += 1
            if a == M:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s2 = []
for _ in range(M):
    s = list(map(int, input().split()))
    del s[0]
    s2.append(s)
p = list(map(int, input().split()))
 
ans = 0
for i in range(2**N):
    judge = True
    for g in range(len(s2)):
        for j in range(M-1):
            count = 0
            s3 = s2[g][j]
            if i >> (s3-1) & 1:
                count += 1
            if count % 2 != p[g]:
                judge = False
    if judge:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s2 = []
for _ in range(M):
    s = list(map(int, input().split()))
    del s[0]
    s2.append(s)
p = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    judge = True
    for g in range(len(s2)):
        for j in range(M-1):
            count = 0
            s3 = s2[g][j]
            if i >> (s3-1) & 1:
                count += 1
            if count % 2 != p[g]:
                judge = False
    if judge:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
card =[[0]*n for _ in range(m)]
for i in range(m):
    switch = list(map(int,input().split()))[1:]
    for k in switch:
        card[i][k-1] = 1
##どこに繋がっているかを配列で表現

#print(card)


ans =list(map(int,input().split()))
cnt=0
from itertools import combinations
##全通りを調べる
for epoch in range(1,n+1):
    
    for j in combinations(range(1,n+1),epoch):
        sco =[]
        for lisa in card:##一つずつの照明について調べる
            score =0
            for l in j:
                score += lisa[l-1]
                
            sco.append(score)
        #print(sco)
        if list(np.array(sco)%2) == ans:
            cnt+=1
            
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
def dfs(A):
    global cnt

    if len(A) == n:
        ans = [0 for i in range(m)]
        print(A)
        for i, a in enumerate(A):
            if a:
                for j in range(m):
                    if i+1 in s[j]:
                        ans[j] += 1
        print(ans)
        for x, y in zip(p, ans):
            if x != y%2:
                break
        else:
            cnt += 1
        return
    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()

n, m = map(int, input().split())
s = [list(map(int, x.split()))[1:]  for x in sys.stdin.readlines()]
p = list(map(int, input().split()))
cnt = 0
dfs([])
print(cnt)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
sw=[[]*m]
for _ in range(m):
    temp=list(map(int,input().split()))
    sw[_]=temp[1:]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    temp=[0]*n
    for j in range(n):
        if i&1: temp[j]=1
        i>>=1
    flag=1
    for l,s in enumerate(sw):
        cnt=0
        for k in s:
            if temp[k-1]==1: cnt+=1
        if p[l]!=cnt%2:
            flag=0
            break
    if flag: ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
pattern.append([0]*m)
pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
count =0
ans=0
n,m = map(int,input().split())
pattern = list(itertools.permutations(range(2), n))
pattern.append([0]*m)
pattern.append([1]*m)

lists =[]
switches = [1]*n
onoff = [0]*m
for i in range(m):
    lists.append(list(map(int,input().split())))
key_value = list(map(int,input().split()))
for l in pattern:
    switches = list(l)
    print(switches)
    for j in range(m):
        for k in range(int(lists[j][0])):
            if switches[k] == 1:
                count += 1
        if count %2 == key_value[j]:
            onoff[j] = 1
        else:
            break
    if not 0 in onoff:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N,M = (int(x) for x in input().split())
a = [0]*N  
k = []
ans = 0
for i in range(M):
  k = [int(x) for x in input().split()]
  for j in range(k[0]): #kよりつながっている電球を一個ずつ見てる
    s = k[j+1]-1
#    print(i,j,s,a[s],a)
    a[s] = a[s] | (1<<i) #aは各スイッチがつながっている電球の情報を保持
#   左端はMとつながっているかどうかを表す。
    #a[0]＝10100はスイッチ０が電球4と電球2とつながっていることを表している。
p = [int(x) for x in input().split()]
P = 0
for i in range(M):
  P |= p[i] << i　
  #Pはpの情報を全て持っている二進数。例えば、P＝10011は電球４、１、０が
  # on になっているスイッチの個数を2で割った余りが１の時点灯するを表す
  #左端がMは統一されている
for s in range(1<<N):　　#1<<N は2**nと同じ
  t = 0
  for i in range(N):
    if ((s>>i) & 1):　#スイッチオンだったら
      t ^= a[i]		
      #これはXORを使って、スイッチがonになっているスイッチの個数を２で割ったあまりを表している
  if (t == P):	#もし、t＝＝Pなら、当てはまっているので、ans++する。
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
N, M = map(int, input().split())
denkyu = []
for i in range(M):
    denkyu.append([int(j) for j in input().split()])
p = [int(i) for i in input().split()]
ls = [0, 1]
ans = 0
for x in product(ls, repeat=N):
    num = 0
    for denkyu_, j in enumerate(denkyu):
        judge_light_on = 0
        for s, i in enumerate(denkyu_):
            if i != 0 and x[s-1] == 1:
                judge_light_on += 1
        if judge_light_on%2 == p[j]:
            num += 1
    if num == 0 or num == M:
        ans += 1
print(ans)

Submission status: Runtime Error

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

k = []
s = []
ans = 0

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

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

for bit in range(1<<n):
    for i in range(m):
        cnt = 0
        for sw in s[i]:
            if bit & 1<<(sw-1):
                cnt += 1
        if cnt % 2 != p[i]:
            break
    else:
        res += 1

print(res)

Submission status: Runtime Error

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

s = []
for i in range(M):
    _, *tmp_s = map(int, input().split())
    s.append(tmp_s)
    
p = list(map(int, input().split()))

import numpy as np

s_matrix = []

for i in range(M):
    s_matrix.append([1 if x+1 in s[i] else 0 for x in range(N)])
    
s_matrix = np.array(s_matrix)

ans = 0

for i in range(2**N):
    on_off_pattern = list(format(i, '0%db' %N))
    on_nums = s_matrix @ np.array(list(map(int, on_off_pattern)))
    on_nums_mod2 = on_nums % 2

    if not False in (on_nums_mod2 == p):
        ans += 1
        
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
k=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))

cnt=0
for i in range(2**n):
  l=[0 for j in range(n)]
  for j in range(n):
    if (i>>j)&1:
      l[j]=1

  t_cnt0
  for j in range(m):
    on_l=0
    for x in k[j][1:]:
      x-=1
      if l[x]==1:
        on_l+=1
    if on_l%2==p[j]:
      t_cnt+=1

  if t_cnt==m:
    cnt+=1

print(cnt)

Submission status: Runtime Error

Solution code:
#１行目の『N M』の取得
N,M=map(int,input().split())

#2-(M+1)行目の取得
switch_li=[[] for _ in range(M)] 
#M個の入れ子のリスト、スイッチの個数、スイッチ何がついているか
for i in range(M):
    li=list(map(int,input().split()))
    switch_li[i].extend(li)
    #appendではなくてextendを使ってリストを展開してから結合する

#スイッチの個数は正直データとして要らないので消す
#del li[0] で値消せる
for i in range(M):
    del switch_li[i][0]
#これでついているスイッチだけを格納したM列の入れ子リストができた

#M+2行目のPの取得
P=list(map(int,input().split()))

#スイッチのつき方の全探索する
#スイッチはN個あり、それが着くか付かないかで、場合の数は、2**N通り
switch_bit=[[] for _ in range(2**N)]
for i in range(2**N):
    for j in range(N):
        if (i>>j)&1==1:
            switch_bit[i].append(j+1)
        else:
            continue
#これで全ての組み合わせを抽出できた（スイッチonのものだけが記載される）

#switch_bitそれぞれについて条件を満たすのかどうか判定する
#まずスイッチ3で考えてみる(具体的でまず考えた方がわかりやすい)、その後それを一般化する
#switch_li{2}の要素をfor文で回して、スイッチonのものに含まれている場合は、リストに追加する
#それを最後に2で割って値を比べる
#まずスイッチ３のままコード書いてあとでそれを修正する
#今は何かスイッチ光っているものが入力されているとする（ここではswitch_bit[i]とする）
#実際実行することを考えると、iでスイッチ光るものを固定（switch_bit）し、j=3でスイッチを固定して光るかどうか判定する


#スイッチのつく組みが与えられている時に、電球がつくかどうか判定する関数を作る
def light_or_not(x,i):
    li=[]
    for k in switch_li[x-1]:
        if k in switch_bit[i]:
            li.append(k)
        else:
            continue
    if len(li)==0:
        return False
    elif len(li)%2==P[x-1]:
        return True
    else:
        return False
    
ans=0
for i in range(2**N):
    for j in range(1,N+2):
        if j==N+1:
            ans+=1
        elif light_or_not(j,i):
            continue
        else:
            break
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N, M = list(map(int, input().split()))
    ks = [[int(arg) for arg in input().split()] for _ in range(M)]
    p = list(map(int, input().split()))
    comb = 0

    for i in range(2**N):
        flag = False
        for j in range(N):
            denki = []
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                denki.append(j+1)  # フラグが立っていたら num に数字を詰める
            for k in range(M):
                KS = ks[k]
                k = KS[0]
                kosuu = 0
                for l in range(1, k+1):
                    if KS[l] in denki:
                        kosuu += 1
                if kosuu % 2 != p[k]:
                    flag = False
                    break
                else:
                    flag = True
            if flag:
                comb += 1

    print(comb)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

ans = 0

for i in range(2**N):
  switch_states = [(i >> j) & 1 for j in range(N)]
  
  for di, d in enumerate(ds):
    count = 0
    for s in d:
      count += switch_states[s-1]
      if count % 2 == P[di]:
        ans += 1
        
        
print(ans)

Submission status: Runtime Error

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

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

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

ans = 0

for i in range(2**N):
  switch_states = [(i >> j) & 1 for j in range(N)]
  
  for di, d in enumerate(ds):
    count = 0
    for s in d:
      count += switch_states[s-1]
      if count % 2 == P[di]:
        ans += 1
        
        
print(ans)

Submission status: Runtime Error

Solution code:
SN,LN=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(LN)]
p=list(map(int,input().split()))

c=0
for i in range(1<<SN):
  tmp=[0]*SN
  for j in range(SN):
    if (i>>j)&1==1:
      tmp[j]=1
      judge=True
  for k in range(LN):
    sum=0
    for x in S[k][1:]:
      if tmp[x-1]==1:
        sum+=1
    if sum%2!=p[k]:
      judge=False
  if judge:
    c+=1

print(c)

Submission status: Runtime Error

Solution code:
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],n):
  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)

Submission status: Runtime Error

Solution code:
import intertools

n , m = map(int,input().split())
sw = [[] for _ in range(m)]
for i in range(m):
    sw[i] = list(map(int,input().split()[1::]))

ans = 0

for tpl in intertools.product([0,1],repeat = n):
    bl = True
    for i in range(m):
        s = sum(tpl[s-1] for s in sw[i])
        if (s-p[i])%2 != 0:
            bl = False
            break
    if bl:
        ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
S = []
for m in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
P = list(map(int, input().split()))

ans = 0
for c in product([0, 1], repeat=N):
    ok = True
    for m in range(M):
        sm = 0
        for s in S[m]:
            sm += c[s - 1]
        if sm % 2 != P[m]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:

#bit & 演算子は同じ位置のbitが１の時１を返す

def main():
    n, m = map(int, input().split())
    # ｋは何個のスイッチにつながっているか、ｓはスイッチの番号
    s = []; k = [] # s : どのスイッチとつながってるか、インデックスは電球を指す、　k: 電球が何個のスイッチとつながっているか
    for _ in range(m):
        tmp_k, *tmp_s = list(map(int, input().split()))
        k.append(tmp_k); s.append(tmp_s)
    p = list(map(int, input().split()))

    res = 0
    # スイッチの状態は２進数表記で表す。スイッチはｎ個あるので
    for bit in range(2**n):
        ok = True
        for i in range(m): # 各電球に対して見ていく
            cnt = 0
            for v in s[i]: # 各電球につながっているスイッチを見てる
                if ( bit & 1 << (v - 1) ): # bitの状態がスイッチvがついてる状態なのかどうか
            if cnt % 2 != p[i]:
                ok = False
        if ok: # okなら全ての電球が付いているということ
            res += 1

    print(res)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

# bit & 演算子は同じ位置のbitが１の時１を返す

def main():
    n, m = map(int, input().split())
    # ｋは何個のスイッチにつながっているか、ｓはスイッチの番号
    s = []; k = [] # s : どのスイッチとつながってるか、インデックスは電球を指す、　k: 電球が何個のスイッチとつながっているか
    for _ in range(m):
        tmp_k, *tmp_s = list(map(int, input().split()))
        k.append(tmp_k); s.append(tmp_s)
    p = list(map(int, input().split()))

    res = 0
    # スイッチの状態は２進数表記で表す。スイッチはｎ個あるので
    for bit in range(2**n):
        ok = True
        for i in range(m): # 各電球に対して見ていく
            cnt = 0
            for v in s[i]: # 各電球につながっているスイッチを見てる
                if ( bit & 1 << (v - 1) ): # bitの状態がスイッチvがついてる状態なのかどうか
            if cnt % 2 != p[i]:
                ok = False
        if ok: # okなら全ての電球が付いているということ
            res += 1

    print(res)



if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from itertools import product
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 bit in product([0, 1], repeat=n):
    onoff = [1] * n # 1がon 0がoff
    ele = True
    for i, j in enumerate(bit):
        if j == 1:
            onoff[i] = 0
    #switchの状態を確認
    #print(bit,i,j)
    for k in range(m):
        cnt = 0
        #print(onoff)
        for l in range(sw[0][k]): #電球のループ
            if onoff[sw[k][l]-1]  == 1:
                cnt += 1
        if cnt % 2 != p[k]:
            ele = False
            break
    if ele :
        ans += 1

        
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import product
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 bit in product([0, 1], repeat=n):
    onoff = [1] * n # 1がon 0がoff
    ele = True
    for i, j in enumerate(bit):
        if j == 1:
            onoff[i] = 0
    #switchの状態を確認
    #print(bit,i,j)
    for k in range(m):
        cnt = 0
        #print(onoff)
        for l in range(sw[0][k]): #電球のループ
            if onoff[sw[k][l]-1]  == 1:
                cnt += 1
        if cnt % 2 != p[m-1]:
            ele = False
            break
    if ele :
        #print(i,j,k,l)
        ans += 1

        
print(ans)

Submission status: Runtime Error

Solution code:
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**M):
    bi = str(bin(i))[2:]
    bi = bi.zfill(M)
    isAddable = True
    for j in range(M):
        s_sum = 0
        for s in S[j]:
            if bi[s-1] == '1':
                s_sum += 1
        if s_sum % 2 != P[j]:
            isAddable = False
            break
    if isAddable:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
#C
n, m = map(int, input().split())
k = [] * m
s = [] * m
p = [] * m
for i in range(m):
    ks = list(map(int, input().split()))
    k.append(ks[0])
    s.append(ks[1:])
p = list(map(int, input().split()))

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