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:
import numpy as np
n,m = map(int,input().split())
k_and_s = list(list(map(int,input().split()))for i in range(m))
p = list(map(int,input().split()))
k = []
s = []
p1 = np.array(p)
print("p1 = ",p1,"\n")
for i in range(m):
    k.append(k_and_s[i][0:1][0])
    s.append(k_and_s[i][1:])
switch = np.array([[0 for i in range(m)]for i in range(n)])
for i in range(len(s)):
    for j in range(len(s[i])):
        switch[s[i][j]-1][i] = 1
ans = 0
for s in range(1<<n):
    t = 0
    for i in range(n):
        if s>>i & 1 == 0:
            t ^= switch[i]
            print("t = ",t,"\n")
            if t == p1:
                ans +=1
            
print("\nswitch = ",switch,"\n")
print("m = ",m)
print("n = ",n)
print("k and s = ",k_and_s)
print("k = ",k)
print("s = ",s)
print("p = ",p1)
#print(len(s))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

denkyu = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
memo = []
memos = []


def erabu(i, n, c, d):
    if (i > len(k[d][1:])):
        if(c % 2 == p[d]):
            memo.append(n)
        return
    if(i+1 in k[d][1:]):
        erabu(i+1, n.append(i+1), c+1, d)
    erabu(i + 1, n, c, d)


print(memo)

for i in range(m):
    erabu(0, 0, 0, i)
    memos.append(memo)

# for i in range(len(memos[0])):

# def isOK(i, n):
 #   if (n ^ memos[i][j] not 0)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
s=[[]]*m
for i in range(m):
  s[i]=list(map(int,input().split()))
  del s[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)

Submission status: Runtime Error

Solution code:
import itertools

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

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

li = [0,1]
ans = 0
for elm in itertools.product(li,repeat=n):
    for i in range(n):
        mm = 0
        for j in range(len(s[i])-1):
            if elm[s[i][j]-1]==1:
                mm += 1
        if mm%2!=p[i]:
            break
    else:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
tl = np.array([0,1,2,1,1,])
tl = np.array([0,1,2,1,1,])
dp = np.zeros((10,10))
ans = 0
n,m = map(int,input().split())
for i in range(10):
    tl = list(map(int,input().split()))
    for j in tl[1:]:
        dp[i][j-1]+=1
l = list(map(int,input().split()))
import itertools
for i in range(1,n+1):
    bp=np.zeros(10)
    t = list(itertools.combinations(range(5), i))
    for j in t:
        bp=np.zeros(10)
        for J in j:
            bp[J]+=1

        s = 0
        for j in range(n):
            s += (np.dot(dp[j],bp))%2 == l[j]
        if s == n: ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
tl = np.array([0,1,2,1,1,])
tl = np.array([0,1,2,1,1,])
dp = np.zeros((10,10))
ans = 0
n,m = map(int,input().split())
for i in range(m):
    tl = list(map(int,input().split()))
    for j in tl[1:]:
        dp[i][j-1]+=1
l = list(map(int,input().split()))
import itertools
for i in range(1,n+1):
    bp=np.zeros(10)
    t = list(itertools.combinations(range(5), i))
    for j in t:
        bp=np.zeros(10)
        for J in j:
            bp[J]+=1

        s = 0
        for j in range(n):
            s += (np.dot(dp[j],bp))%2 == l[j]
        if s == n: ans +=1
print(ans)

Submission status: Runtime Error

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

for i in range(2**n):
    on = True
    for j in range(m):
        on = bin(s[j]&i)lcount('1')%2 == p[j]
        if not on:
            break
    ans += on
print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
s=[] #全kについて、スイッチの状態を格納する。s[][]で呼び出し
for i in range(m):
	switch=[] #各kについて、スイッチの状態を一旦格納する
	k,*switch=map(int,input().split())
	#switch[i]はswitchの番号であり[1,n]なので、インデックスを1つずつ減らす
	for i in range(k):
		switch[i]-=1
	s.append(switch)
p=list(map(int,input().split()))
'''
print(p) ->[1, 0]
print(s) ->[[0, 1, 4], [1, 2]]
'''
'''
state=format(4,'b')
state=state.zfill(n)
print(state)
print(s[1][1])
print(state[s[1][1]])
'''
count=0
for i in range(2**n):
	q=[] #各状態に対して、各電球につながっているスイッチのon数の偶奇を格納する配列
	state=format(i,'b')
	state=state.zfill(n)
	for i in range(m):
		on=0
		for j in range(k):
			on+=int(state[s[i][j]])
		on=on%2
		q.append(on)
		
	allon=1
	for i in range(m):
		if p[i]!=q[i]:
			allon=0
			break
	if allon:
		count+=1
print(count)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
mod = 10**9+7
fram = [1]
for i in range(1,N+1):
  fram.append(fram[-1]*i%mod)

#def framod(n, mod, a=1):
#    for i in range(1,n+1):
#        a = a * i % mod
#    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=fram[n]
    b=fram[k]
    c=fram[n-k]
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

def cnt(n):
  s = sum([comb(n-i,i,mod)%mod for i in range(n//2+1)])
  s = s%mod
  return s

A0 = 0
ans = 1
for i in range(M):
  A1 = int(input()) - 1
  ans = (ans * cnt(A1-A0))%mod
  A0 = A1+2
ans = (ans * cnt(N-A0))%mod
print(ans)

Submission status: Runtime Error

Solution code:
s = []
for i in range(m):
  st = list(map(int, input().split()))
  s.append(st[1 :])
  p = list(map(int, input().split()))

  ans = 0
  #あるつき方について
  for i in range(1 << n):
    al = True
    #つき方二進数
    v = [bool(i & (1 << x)) for x in range(n)]
    #電球全体
    for j in range(m):
      #onになってるスイッチの個数
      num = 0
      #スイッチの番号
      for t in s[j]:
        num += v[t - 1]
        if p[j] != num % 2:
          al = False
          ans += al
          print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
k=[]
ans=0
for i in range(m):
      a=list(map(int,input().split()))
      k.append(a)
p=list(map(int,input().split()))
for i in range(2**n):
      L=[0]*n
      for j in range(n):
            if ((i>>j)&1):
                  L[j]=1
      flag=True
      for j in range(n):
            s=0
            for e in range(k[j][0]):
                  s+=L[k[j][e+1]-1]
            if s%2!=p[j]:
                  flag=False
      if flag:
            ans+=1
print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(1 << n):
    v = [1 - i for i in p]
    for j in range(m):
        if (i & (1 << j)):
            for t in s[j]:
                v[t - 1] = 1 - v[t - 1]
    if sum(v) == m:
        ans += 1
    #print(i, v)
print(ans)

Submission status: Runtime Error

Solution code:
import copy

N,M = map(int, input().split())
jisho = [[] for i in range(N)]
for i in range(M):
    val = input().split()
    for j in val[1:]:
        jisho[int(j)-1].append(i)

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

sw = []
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

ans = 0
for val in sw:
    num = 0
    sw2 = [0]*M
    for i in val:
        if i == 0:
            num += 1
            continue
        data = jisho[num]
        for j in data:
            sw2[j] += 1
        num += 1
    cn = 0
    for j in sw2:
        if j % 2 == p[cn]:
            break
        cn += 1
    if cn == M:
        ans += 1

print(ans)
mac:128 ry

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
k = list()
for i in range(m):
    k.append(map(int,input().split()))
p = list(map(int,input().split()))
s = [0 for i in range(n)]
ans = 0
def switch(num):
    global count,ans,s,k
    for i in [0,1]:
        if num == n:
            count = 0
            flag = True
        if num != 1:
            s[n-num] = i
            switch(num-1)
        else:
            s[n-num] = i
            for j in range(m):
                print(k)
                print(k[j])
                u = list(k[j]) #電球jのスイッチについて考える
                for k in range(1,len(u)):
                    count += s[u[k]-1]
                if count % 2 != p[j]:
                    flag = False
            if flag:
                ans += 1
switch(n)
print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n,m = map(int,(input().split()))
bulb = [0]*m
p = [0]*m
j = 1
odd = 0
even = 0
for i in range(m):
    bulb[i] = list(map(int,input().split()))
p = list(map(int,input().split()))

for i in range(m):
    if not bulb[i][0]%2==p[i]:
        print(0)
        exit()
    elif bulb[i][0]%2==0:
        for j in range(0,bulb[i][0]+1,2):
            even = even + comb(bulb[i][0],j, exact=True)

        if len(bulb[i])==2:
            even = even/2
            
    else:
        for j in range(1,bulb[i][0]+1,2):
            odd = odd + comb(bulb[i][0],j, exact=True)

        if len(bulb[i])==2:
            odd = odd/2              
print(int(odd*even))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n,m = map(int,(input().split()))
bulb = [0]*m
p = [0]*m
j = 1
odd = 0
even = 0
for i in range(m):
    bulb[i] = list(map(int,input().split()))
p = list(map(int,input().split()))
 
for i in range(m):
    if not bulb[i][0]%2==p[i]:
        print(0)
        exit()
    elif bulb[i][0]%2==0:
        for j in range(0,bulb[i][0]+1,2):
            even = even + comb(bulb[i][0],j, exact=True)
            
        if len(bulb[i])==2:
            even = even/2
            
    else:
        for j in range(1,bulb[i][0]+1,2):
            odd = odd + comb(bulb[i][0],j, exact=True)
          
        if len(bulb[i])==2:
            odd = odd/2              
 
print(int(odd*even))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n,m = map(int,(input().split()))
bulb = [0]*m
p = [0]*m
j = 1
odd = 0
even = 0
for i in range(m):
    bulb[i] = list(map(int,input().split()))
p = list(map(int,input().split()))

for i in range(m):
    print('bulb='+str(bulb[i][0]))
    if not bulb[i][0]%2==p[i]:
        print(0)
        exit()
    elif bulb[i][0]%2==0:
        for j in range(0,bulb[i][0]+1,2):
            even = even + comb(bulb[i][0],j, exact=True)
            
        if len(bulb[i])==2:
            even = even/2
            
    else:
        for j in range(1,bulb[i][0]+1,2):
            odd = odd + comb(bulb[i][0],j, exact=True)
          
        if len(bulb[i])==2:
            odd = odd/2              

print(int(odd*even))

Submission status: Runtime Error

Solution code:
N,M = map(int,input())
S = []
K = []
for i in range(M):
    s = list(map(int,input().split()))
    k = s.pop(0)
    S.append(s)
    K.append(k)
P = list(map(int,input().split()))
for i in range(2**N):
    sw = [0]*N
    for j in range(N):
        if (i>>j)&1:
            sw[j] = 1
    flag = 1
    for m in range(M):
        po = S[m]
        sum = 0
        for k in range(K[m]):
            if sw[po[k]-1] == 1:
                sum = (sum + 1)%2
        if P[m] != sum:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def p_c():
    N, M = map(int, input().split())
    switch = [0] * N
    light = [0] * (1 << M)
    light[0] = 1
    for i in range(M):
        for s in list(map(int, input().split()))[1:]:
            switch[s - 1] += (1 << i)

    all_value = 0
    ps = list(map(int, input().split()))
    for i, p in enumerate(ps):
        all_value += p << (M - i - 1)

    for i in range(N):
        next_light = light.copy()
        for j in range(len(light)):
            next_light[j ^ switch[i]] += light[j]
        light = next_light

    print(light[all_value])
    
p_c()

Submission status: Runtime Error

Solution code:
def p_c():
    N, M = map(int, input().split())
    switch = [0] * N
    light = [0] * (1 << M)
    light[0] = 1
    for i in range(M):
        for s in list(map(int, input().split()))[1:]:
            switch[s - 1] += (1 << i)

    all_value = 0
    for i, p in enumerate(map(int, input().split())):
        all_value += p << (M - i - 1)

    for i in range(N):
        next_light = light.copy()
        for j in range(len(light)):
            next_light[j ^ switch[i]] += light[j]
        light = next_light

    print(light[all_value])
    
p_c()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
for x in range(2 ** N + 1):
#     print("===========", x, ans)
    for m in range(M):
        c = 0
        for k in range(1, ks_list[m][0]+1):
            ks_mk = -ks_list[m][k]
            if int(format(x,'b').zfill(10)[ks_mk]) == 1:
                c += 1
#             print(ks_list, ks_list[m][k], ks_mk, format(x,'b').zfill(10), format(x,'b').zfill(10)[ks_mk])
#         print(c, p[m])
        if c % 2 != p[m]:
#             print("break")
            break
        if m == M-1:
            ans += 1
#     print(ans, ks_list, c, p)

print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

typedef long long int ll;
using namespace std;

const ll MOD = 1e9 + 7;

int bit_count(int x){
	if(x==0)return 0;
	return x%2 + bit_count(x/2);
}

int main()
{
	int n,m; cin>>n>>m;
	int c[12]={0}; int p[12];
	for(int i=0;i<m;i++){
		int k; cin>>k;
		while(k--){
			int t; cin>>t; --t;
			c[i] ^= (1<<t);
		}
		//cout<<c[i]<<endl;
	}
	for(int i=0;i<m;i++) cin>>p[i];

	int ans=0;
	for(int i=0;i<(1<<n);i++){
		int f=0;
		for(int j=0;j<m;j++){
			int t = i&c[j];
			t = bit_count(t);
			if(t%2 == p[j]%2) f++;
		}
		if(f == m) ans++;
	}

	cout<<ans;
}

Submission status: Runtime Error

Solution code:
from numpy import*
n, m = map(int, input().split())
l = []
for i in range(m):
    *a,=map(int,input().split())
    l.append(a[1:])
*p,=map(int,input().split())
ans = 0
for t in range(2**n):
    for s in range(n):
        tmp = array([t >> s & 1])
    for i in l:
        if p == sum(tmp[array(i)-1])%2:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    # n,m の先行受け取り
    n,m = map(int, input().split())
    # コンテナの準備
    k=[0 for i in range(n)]     # それぞれの電球(light)に繋がれたスイッチ(swuitch)の個数を表す
    # s=[0 for i in range(n)]     # それぞれの電球(light)に繋がれている「スイッチ(switch)」を表す
    
    S=[ [] for i in range(m)]
    for i in range(m):
        S[i]=[ 0 for i in range( k[i] ) ]

    # 入力
    for i in range(m):
        l = list(map(int, input().split()))
        k[i] = l[0]
        ll=l[1:]
        for j in range(len(ll)):
            ll[j]=ll[j]-1
        S[i] = ll
    p = list(map(int, input().split()))

    # 出力
    eprint()
    # print(n,m)
    eprint("num of Switch : " + str(n) + "    num of Light : " + str(m))
    for i in range(m):
        # print(k[i],S[i])
        eprint("k[%d]: %d      S[%d]: " % (i,k[i],i ) + str(S[i]) )
    eprint("p: "+ str(p))

    # 処理
    cnt_state_whereLightIsTurnedOn=0
    
    for state in range(2**n):   # stateは状態(ステート)を表す整数
        failure_flag=0
        for index in range(m):  # indexは電灯の番号を表すインデックス
            cnt=0
            for i in range(k[index]): # i is the "uniform_number" of Switches
                if (state>>S[index][i] & 1)==1 :
                    cnt+=1
                    
            if cnt%2==p[index]:
                # failure_flag=0
                # cnt_state_whereLightIsTurnedOn+=1
                continue
            else:
                failure_flag=1
                break
                print(cnt_state_whereLightIsTurnedOn)
        if failure_flag==0:
            cnt_state_whereLightIsTurnedOn+=1
        else:
            continue
        
    print(cnt_state_whereLightIsTurnedOn)
    return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    # n,m の先行受け取り
    n,m = map(int, input().split())
    # コンテナの準備
    k=[0 for i in range(n)]     # それぞれの電球(light)に繋がれたスイッチ(swuitch)の個数を表す
    # s=[0 for i in range(n)]     # それぞれの電球(light)に繋がれている「スイッチ(switch)」を表す
    
    S=[ [] for i in range(m)]
    for i in range(m):
        S[i]=[ 0 for i in range( k[i] ) ]

    # 入力
    for i in range(m):
        l = list(map(int, input().split()))
        k[i] = l[0]
        ll=l[1:]
        for j in range(len(ll)):
            ll[j]=ll[j]-1
        S[i] = ll
    p = list(map(int, input().split()))

    # 出力
    eprint()
    # print(n,m)
    eprint("num of Switch : " + str(n) + "    num of Light : " + str(m))
    for i in range(m):
        # print(k[i],S[i])
        eprint("k[%d]: %d      S[%d]: " % (i,k[i],i ) + str(S[i]) )
    print("p: "+ str(p))

    # 処理
    cnt_state_whereLightIsTurnedOn=0
    
    for state in range(2**n):   # stateは状態(ステート)を表す整数
        failure_flag=0
        for index in range(m):  # indexは電灯の番号を表すインデックス
            cnt=0
            for i in range(k[index]): # i is the "uniform_number" of Switches
                if (state>>S[index][i] & 1)==1 :
                    cnt+=1
                    
            if cnt%2==p[index]:
                # failure_flag=0
                # cnt_state_whereLightIsTurnedOn+=1
                continue
            else:
                failure_flag=1
                break
                print(cnt_state_whereLightIsTurnedOn)
        if failure_flag==0:
            cnt_state_whereLightIsTurnedOn+=1
        else:
            continue
        
    print(cnt_state_whereLightIsTurnedOn)
    return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
s=[list(map(int,input().split()))for i in range(m)]
for i in range(m):
    del s[i][0]
p=list(map(int,input().split()))
q=[0]*10


ans=0
for k in range(2*11):
    for i in range(n+1):
        if(q[i]==2):
            q[i+1]+=1
            q[i]=0
    if(q[n]==1):
        break
    
    flag=1
    for i in range(m):
        tmp=0
        for j in s[i]:
            tmp+=q[j-1]
        if(tmp%2!=p[i]):
            flag=0
            break
    if(flag==1):
        ans+=1
    q[0]+=1

print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
s=[list(map(int,input().split()))for i in range(m)]
for i in range(m):
    del s[i][0]
p=list(map(int,input().split()))
q=[0]*10


ans=0
while(True):
    for i in range(n+1):
        if(q[i]==2):
            q[i+1]+=1
            q[i]=0
    if(q[n]==1):
        break
    
    flag=1
    for i in range(m):
        tmp=0
        for j in s[i]:
            tmp+=q[j-1]
        if(tmp%2!=p[i]):
            flag=0
            break
    if(flag==1):
        ans+=1

    q[0]+=1

print(ans)

Submission status: Runtime Error

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

s=[[0 for i in range(N)] for j in range(M)]

for i in range(M):
    tmp=list(map(int,input().split()))

    k=tmp[0]
    for j in range(k):
        s[i][tmp[j+1]-1]=1

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

out=0

for i in range(2**N):
    b=list(map(int,list(bin(i))[2:]))
    b=[0 * (N-len(b))]+b
    ss=1
    for j in range(M):
        t=0
        for k in range(N):
            if b[k]==s[j][k]:
                t+=1
        if t%2!=p[j]:
            ss=0
    if ss==1:
        out+=1

print(out)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
	int N, M; cin >> N >> M;

	vector<vector<int>> vec(M);

	for (int i = 0; i < M; ++i) {
		int k; cin >> k;
		vec[i].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> vec[i][j];
			--vec[i][j];
		}
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i) cin >> p[i];

	int ans = 0;
	for (int i = 0; i < (1 << N); ++i) {
		bool ok = true;
		for (int j = 0; j < M; ++j) {
			int c = 0;
			for (int id : vec[j]) {
				if ((i >> id) & 1) {
					++c;
				}
			}
			c %= 2;
			if (c != p[j]) {
				ok = false;
			}
		}
		if (ok) {
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
K_S = [0]*N
for i in range(N):
    K_S[i] = list(map(int, input().split()))
p = list(map(int, input().split()))

ans = 0
for i in range(2 ** N):
    switch_onoff = [0]*N
    tmp = i
    for j in range(N):
        if tmp % 2 == 1:
            switch_onoff[j] = 1
        tmp = tmp // 2
    flag = True
    for j in range(M):
        count = 0
        for k in range(1, K_S[j][0] + 1):
            count += switch_onoff[K_S[j][k] - 1]
        if count % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
l=[]*M

for i in range(M):
    l.append(list(map(int,input().split())))
    l[i].pop(0)
    
p=list(map(int,input().split()))

count=0
s=[-1]*10

for i in range(2):
    s[0]=i
    for ii in range(2):
        s[1]=ii
        for iii in range(2):
            s[2]=iii
            for iiii in range(2):
                s[3]=iiii
                for iiiii in range(2):
                    s[4]=iiiii
                    for iiiiii in range(2):
                        s[5]=iiiiii
                        for iiiiiii in range(2):
                            s[6]=iiiiiii
                            for iiiiiiii in range(2):
                                s[7]=iiiiiiii
                                for iiiiiiiii in range(2):
                                    s[8]=iiiiiiiii
                                    for iiiiiiiiii in range(2):
                                        s[9]=iiiiiiiiii
                                        #いかれてる
                                        for j in range(M):
                                            sum=0
                                            is_success=True
                                            for item in l[j]:
                                                sum=sum^s[item]
                                            if sum!=p[j]:
                                                is_success=False
                                                break
                                        if is_success:
                                            count+=1
                                            
print(count/2**(10-N))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
#くそ
N,M=map(int,input().split())
l=[]*M

for i in range(M):
    l.append(list(map(int,input().split())))

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

count=0
s=[-1]*10

for i in range(2):
    s[0]=i
    for ii in range(2):
        s[1]=ii
        for iii in range(2):
            s[2]=iii
            for iiii in range(2):
                s[3]=iiii
                for iiiii in range(2):
                    s[4]=iiiii
                    for iiiiii in range(2):
                        s[5]=iiiiii
                        for iiiiiii in range(2):
                            s[6]=iiiiiii
                            for iiiiiiii in range(2):
                                s[7]=iiiiiiii
                                for iiiiiiiii in range(2):
                                    s[8]=iiiiiiiii
                                    for iiiiiiiiii in range(2):
                                        s[9]=iiiiiiiiii
                                        #いかれてる
                                        for j in range(M):
                                            sum=0
                                            is_success=True
                                            for item in l[j]:
                                                sum=sum^s[item]
                                            if sum!=p[j]:
                                                is_success=False
                                                break
                                        if is_success:
                                            count+=1
                                            
print(count/2**(10-N))

Submission status: Runtime Error

Solution code:
S = []
N,M = map(int,input().split())
for i in range(M):
    tmp = [int(i) for i in input().split()]
    K.append(tmp[0])
    tmp.pop(0)
    S.append(tmp)
P = [int(i) for i in input().split()]
List = []
for i in range(2**N):
    tmp = []
    for j in range(N):
        if ((i>>j) & 1):
            tmp.append('1')
        else:
            tmp.append('0')
    List.append(tmp)

for i in range(M):
    kouho = []
    for j in range(len(List)):
        cnt = 0
        for k in range(len(List[j])):
            if List[j][k] == '1':
                """if  not (k+1) in S[i]:
                    if not List[j] in kouho:
                        kouho.append(List[j])
                    break"""
                if k+1 in S[i]:
                    cnt += 1
        if cnt % 2 != P[i] and not List[j] in kouho:
            kouho.append(List[j])
    for x in kouho:
        List.remove(x)
print(len(List))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

switch = [['0'], ['1']]

for i in range(n-1):
    tmp = []
    for j in switch:
        tmp.append(j+['0'])
        tmp.append(j+['1'])
    switch = tmp　#スイッチのonoffのマップ化

ans = 0

for i in switch:
    false = 0
    for j in range(M):
        cnt = 0 #onの個数
        for k in range(s[i][0]):
            if i[s[j][1+k]-1] == '1':
                cnt += 1
            if cnt%2 != p[j]:
                false += 1 #条件に合っていなかったらfalseに加算する
        if false == 0:
            ans += 1 #全て条件を満たしていたらansに加算する
print(ans)

Submission status: Runtime Error

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

onoff=[["0"],["1"]]

for i in range(n):
    tmp=[]
    for j in onoff:
        tmp.append(j+["0"])
        tmp.append(j+["1"])
    onoff=tmp

ans=0
for i in onoff:
    f=0
    for j in range(m):
        c=0
        for k in range(s[j][0]):
            if onoff[s[j][i+k]-1]=="1":
                c+=1
        if c%2!=p[j]:
            f+=1
    if f==0:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
give up