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: Wrong Answer

Solution code:
def solve(switch_state, depth):
    if depth == 0:
        yield switch_state
    else:
        yield from solve(switch_state + [0], depth - 1) # off
        yield from solve(switch_state + [1], depth - 1) # on

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

k_list = []
s_matrix = []

for _ in range(0, m):
    tmp = list(map(int, input().split()))
    k_list.append(tmp[0])
    s_matrix.append(tmp[1:])

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

switch_to_light = {}
for i, s_list in enumerate(s_matrix):
    for s in s_list:
        if s in switch_to_light:
            switch_to_light[s].append(i)
        else:
            switch_to_light[s] = [i]

count = 0
for switch_state in solve([], max(switch_to_light.keys())):
    is_all_light_on = True 
    for i, s_list in enumerate(s_matrix):
        sum_of_on = 0
        for s in s_list:
            sum_of_on = sum_of_on + switch_state[s - 1]
        if sum_of_on % 2 != p_list[i]:
            is_all_light_on = False
            break
    if is_all_light_on:
        count = count + 1

print(count)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    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 = sum([int(i >> j & 1 and j in lamps[r]) for j in range(N)])
            print(on_sum)
            #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)


brute_force()

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    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 = sum([int(i >> j and j in lamps[r]) for j in range(N)])
            print(on_sum)
            #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)


brute_force()

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    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 = sum([i >> j and j in lamps[r] for j in range(N)])
            #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)


brute_force()

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


brute_force()

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


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


brute_force()

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
binlist=[]
for iii in range(m):
  ks=[int(_) for _ in input().split()]
  k=ks[0]
  s=ks[1:]
  binn=0
  for kkk in range(k):
    binn+=2**(s[kkk]-1)
  binlist.append(binn)
q=[int(_) for _ in input().split()]
cnt=0
for iii in range(2**n):
  res=[]
  for jjj in binlist:
    res.append(bin(jjj & iii).count("1")%2)
  if res==q:
    cnt+=1

    print(cnt)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
s = []
p = []
for i in range(M):
    s.append([int(i) for i in input().split()])
p.append(map(int,input().split()))
cnt = 0
for i in s:
    for j in i:
        for t in range(len(p)):
            if (j // 2) == p[t]:
                cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def brute_force():
    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(M):
                if i >> j & 1 and j in lamps[r]:
                    on_sum += 1
            if on_sum % 2 == p[r]:
                continue
            else:
                break
        else:
            ans += 1
    print(ans)


brute_force()

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
s=[list(map(int,input().split())) for i in range(M)]
p=list(map(int,input().split()))
ans=0
for i in range(2**N):
  ptn=bin(i)[2:].rjust(N,'0')
  light=True
  for j in range(M):
    tmp=0
    for n in range(1,s[j][0]+1):
      if ptn[s[j][n]-1]=='1':
        tmp+=1
      if tmp%2!=p[j]:
        light=False
    if light==True:
      ans+=1
print(ans)

Submission status: Wrong Answer

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

p=list(map(bool,input().split()))
p=list(map(lambda x:not x,p))

for i in range(2**n):
    tmp_p=p[:]#shallow copy
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                if j+1 in s[k]:
                    tmp_p[k]^=True#toggle

    if all(tmp_p):
        count+=1

print(count)

Submission status: Wrong Answer

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

p=list(map(bool,input().split()))
p=list(map(lambda x:not x,p))

for i in range(2**n):
    tmp_p=p[:]#shallow copy
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                if j+1 in s[k]:
                    tmp_p[k]^=True#toggle

    if all(tmp_p):
        count+=1
        print(bin(i))
print(count)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
lightList = []
for _ in range(M):
    lightList.append(list(map(int, input().split())))
P = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    flag = True
    for a in range(M):
        cnt = 0
        for b in lightList[a][1:]:
            if not (i & (1<<b)):
                cnt += 1
        if cnt % 2 != P[a]:
            flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
list_Connect=[]
for i in range(M):
    A = list(map(int, input().split()))
    A.pop(0)
    list_Connect.append( A )

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

print ("list_Connect",list_Connect)
print("list_p",list_p)
i = 0



state = []#スイッチ点灯の全組み合わせを入れる
sum=0

def func(i):
    global sum
    print(state)
    if i == N:
        flag = True
        for i in range(M):
            cnt= 0
            for j in list_Connect[i]:
                cnt += state[j-1]
            if cnt %2 != list_p[i]:
                print("j ",j)
                flag = False
                break
        if flag == True:
           sum+=1
    else:
        state.append(1)
        func(i+1)
        state.pop(-1)
        state.append(0)
        func(i+1)
        state.pop(-1)

    return


func(0)
print ("答えは",sum)

Submission status: Wrong Answer

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

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

# print("switches : {}".format(switches))
# print("p : {}".format(p))

switches_pattern = []
for i in range(2**n):
    if i == 0:
        continue
    switches_pattern.append(list(map(int, format(i, "b").zfill(n))))

# print(switches_pattern)

result = 0
for pattern in switches_pattern:
    light_bulb = True
    for i in range(m):
        bulb_count = 0
        for bulb_index in switches[i][1:]:
            if pattern[bulb_index - 1] == 1:
                bulb_count += 1
        if bulb_count % 2 == p[i]:
            pass
        else:
            light_bulb = False

    if light_bulb:
        result += 1

print(result)

Submission status: Wrong Answer

Solution code:
def main():
	N, M = map(int, input().split())
	S = [[] for _ in range(N)]

	for i in range(M):
		s = list(map(int, input().split()))
		for sw in s[1:]:
			S[sw-1].append(i)
	P = list(map(int, input().split()))
	num = 2**N
	ans = 0
	for n in range(num):
		cur = [0]*M
		for j in range(N):
			if (n >> j)&1 == 1:
				for e in S[j]:
					cur[e-1] += 1
		is_add = True
		for i, c in enumerate(cur):
			if c%2 != P[i]:
				is_add = False
				break
		if is_add:
			ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	N, M = map(int, input().split())
	S = [[] for _ in range(N)]

	for i in range(M):
		s = list(map(int, input().split()))
		for sw in s[1:]:
			S[sw-1].append(i)
	P = list(map(int, input().split()))
	num = 2**N
	ans = 0
	for n in range(num):
		cur = list(P)
		for j in range(N):
			if (n >> j)&1 == 1:
				for e in S[j]:
					if cur[e-1] == 0:
						cur[e-1] = 1
					else:
						cur[e-1] = 0
		if all(x == 0 for x in cur):
			ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	N, M = map(int, input().split())
	S = [[] for _ in range(N)]

	for i in range(M):
		s = list(map(int, input().split()))
		for sw in s[1:]:
			S[sw-1].append(i)
	P = list(map(int, input().split()))
	num = 2**N
	ans = 0
	for n in range(num):
		j = 0
		cur = list(P)
		while n >> j > 0:
			if (n >> j)&1 == 1:
				for e in S[j]:
					if cur[e-1] == 0:
						cur[e-1] = 1
					else:
						cur[e-1] = 0
			j += 1
		if all(x == 0 for x in cur):
			ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def sum(A):
    a=0
    for num in range(len(A)):
        a=a+A[num]
    return a
             


N,M=input().split()
N=int(N)
M=int(M)
K=[100]*(M+1)
for num in range(M+1):
    K[num]=input().split()
    for num2 in range(len(K[num])):
        K[num][num2]=int(K[num][num2])

a=[0]*N
cnt=0
for num in range(pow(2,N)):
    flag=0
    n=num
    i=0
    while(N>i):
        a[N-1-i]=n//pow(2,N-1-i)
        if(a[N-1-i]==1):
            n=n-pow(2,N-1-i)
        i=i+1
    b=0
    for num2 in range(M):
        for num3 in range(len(K[num2])-1):
            b=b+a[K[num2][num3+1]-1]
        if(b%2!=K[M][num2]):
            flag=1
    if(flag==0):
        cnt=cnt+1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
bulbs = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
cmb = [1] * 2 ** n

for i in range(2 ** n):
    on_off = [0] * n
    for j in range(n):
        if i >> j & 1:
            on_off[j] = 1
    
    cnt = 0
    for j in range(m):
        for k in bulbs[j][1:]:
            cnt += on_off[k - 1]
        if cnt % 2 != p[j]:
            cmb[i] = 0
            
print(sum(cmb))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
sw = []
ki = []
counter = 0
for i in range(m):
    inp = list(map(int, input().split()))
    sw.append(inp[1:])
    ki.append(inp[0])
criterion = list(map(int, input().split()))
for switch in range(2**n):
    flash = list(range(m))     #flash+criterion%2 = 0なら発光
    for j in range(n):
        if ((switch >> j) & 1):
            for light in range(m):  
                if (j + 1) in sw[light]:
                    flash[light] += 1
    token = True
    for light in range(m):
        if (flash[light] + criterion[light]) % 2 == 1:
            token = False
    if token:
        counter+= 1
print(counter)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
connection = []
switch_num = []
criterion = []
counter = 0
for i in range(m):
    switchnum_connection = input().split()
    switch_num.append(int(switchnum_connection[0]))
    con = []
    for j in range(switch_num[i]):
        con.append(int(switchnum_connection[j+1]))
    connection.append(con)
#print(connection)
crit = input().split()
for i in crit:
    criterion.append(int(i))
for switch in range(2**n):
    switch_str = format(switch, '0{}b'.format(n))
    state = []
    count = 0
    token = 1
    for bi in switch_str:
        state.append(int(bi))
    for light in range(m):    
        for j in range(switch_num[light]):
            #print(state)
            count += state[connection[light][j]-1]
        if (count + criterion[light]) % 2 == 1:
            token = 0
    if token == 1:
        counter += 1

print(counter)

Submission status: Wrong Answer

Solution code:
from itertools import product

n, m = map(int, input().split())
ss = product([0, 1], repeat=n)
lb = []
for i in range(m):
    tmp = list(map(int, input().split()))
    k = tmp.pop(0)
    lb.append(tmp)
p = list(map(int, input().split()))
ans = 0
# n個スイッチのパターンループ
for state in ss:
    flag = True
    sc = 0
    # 電球のスイッチ条件1～iループ
    for j, l in enumerate(lb):
        # 電球の条件取り出し
        for s in l:
            sc += state[s-1]
        if sc % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# 誤答
import sys 
input = sys.stdin.readline

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

li = []

for i in range(2**n):
  i_bin = format(i, 'b').zfill(n)
  li.append(i_bin)
  
S = []
for i in range(m):
  s = list(map(int,input().split()))[1:]
  S.append(s)
   
p = list(map(int,input().split()))

for i in range(m):
  for j in li:
    count = 0
    for k in S[i]:
      count += int(j[k-1])
    if count % 2 != p[i]:
      li.remove(j)
      
print(len(li)) #answer

Submission status: Wrong Answer

Solution code:
import itertools

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

switch = range(1,N+1)
pattern = []
for i in range(1,N+1):
    pattern.extend(tuple(itertools.combinations(switch, i)))

count = 0
for swp in pattern:
    for p, s in zip(P,S):
        match = len(set(s) & set(swp))
        if match == 0:
            break
        if match % 2 != p:
            break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools

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

switch = range(1,N+1)
pattern = []
for i in range(1,N+1):
    pattern.extend(tuple(itertools.combinations(switch, i)))

count = 0
for swp in pattern:
    for p, s in zip(P,S):
        match = len(set(s) & set(swp))
        #if match == 0:
        #    break
        if match % 2 != p:
            break
    else:
        count += 1
print(count)

Submission status: Wrong Answer

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

# m行分配列に放り込む
KS_lis = [list(map(int, input().split())) for _ in range(M)]

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

KS = []
bin_s = ''
ans = 0

for i in range(2**N):

    for j in range(M):
        Z = [0]*N
        KS = KS_lis[j]
        K = KS[0]
        S = KS[1:]

        for l in range(K):
            Z[N-S[l-1]] += 1

        bin_s = ''

        for x in Z:
            bin_s += str(x)

        if bin(i & int(bin_s)).count("1") % 2 != P[j]:
            break
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

for i in range(2**n):
    res+=1
    for j in range(len(arr)):
        on = 0
        for k in range(arr[j][0]):
            on += i>>(arr[j][k+1])
        if (on%2 != p[j]):
            res -=1
            break
print (res)

Submission status: Wrong Answer

Solution code:
from collections import deque, _heapq
N, K = map(int, input().split())
V = deque(map(int, input().split()))

class Money:
    def __init__(self):
        self.yen = 0
        self.red = []

    def value(self):
        return self.yen + sum(self.red)

    def add(self, yen):
        if yen >= 0:
            self.yen += yen
        else:
            self.red.append(yen)

    def remove(self, yen):
        if yen >= 0:
            self.yen -= yen
        else:
            self.red.remove(yen)

mny = Money()
def get(cnt, mny, lstop, rstop):
    ans = mny.value()

    if cnt <= 0:
        return ans

    if len(V) > 0:

        if lstop == 0:
            w = V.popleft()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, lstop, rstop))
            mny.remove(w)
            V.appendleft(w)
        elif lstop > 0:
            lstop -= 1

        if rstop == 0:
            w = V.pop()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, 1, rstop))
            mny.remove(w)
            V.append(w)

    if len(mny.red) >= cnt:
        w = min(mny.red)
        mny.red.remove(w)

        V.appendleft(w)
        ans = max(ans, get(cnt-1, mny, -1, rstop))
        V.popleft()

        V.append(w)
        ans = max(ans, get(cnt-1, mny, lstop, -1))
        V.pop()

        mny.red.append(w)    

    return ans

print(get(K, Money(), 0, 0))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
connect = []
for j in range(M):
    connect.append(list(map(int, input().split())))
plist = list(map(int, input().split()))

count = 0
for n in range(2**N):
  for j in range(M):
    connect_score = sum(connect[j][1:])
    switch_on = n & connect_score
    num_switch_on = [int(k) for k in str(bin(switch_on))[2:]]
    if (sum(np.array(num_switch_on)) % 2) != plist[j]:
  		 break
    if j == M-1:
        count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
res = 0
Q = []
for i in range(m):
    Q.append(list(map(int,input().split()))[1:])
P = list(map(int,input().split()))

for s in range(2**n):
    tmp = 0
    for q in Q:
        cnt = 0
        for t in q:
            if s>>(t-1) &1 == 1:
                cnt += 1
        if cnt % 2 == P[i]:
            tmp += 1
    if tmp == m:
        res += 1
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
connect = [0] * M
for j in range(M):
  connect_list = [int(s) for s in input().split()[1:]]
  connect[j] = sum(np.array(connect_list))
plist = list(map(int, input().split()))

count = 0
for n in range(2**N):
  for j in range(M):
    switch_on = n & connect[j]
    num_switch_on = [int(k) for k in str(bin(switch_on))[2:]]
    if (sum(np.array(num_switch_on)) % 2) != plist[j]:
  		 break
    if j == M-1:
        count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int,input().split())

ks = np.array([list(map(int,input().split()[1:])) for _ in range(m)])

ss = np.array(list(map(int,input().split())))

def ans(n):
    return(b1(n,[])+b0(n,[]))

def b0(n,t):
    global ss
    if n == 2:
        return 0
    return b0(n-1,t)+b1(n-1,t)

def b1(n,t):
    global ks
    global ss
    t = np.array([int(n in k) for k in ks])
    if n == 2:
        return all([i%2 for i,j in zip(t,ss)])
    return b0(n-1,t)+b1(n-1,t)

print(ans(n))

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [j for j in P]
  for j in range(M):
    for s in S[j]:
#      print(list(map(int,bin(i + 2 ** (N + 1))[4:])),s)
      if list(map(int,bin(i + 2 ** (N + 1))[4:]))[s - 1] == 1:
        p[j - 1] += 1
  if all([r % 2 == 0 for r in p]):
    ans += 1
#  print(P,p,ans)
  
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [j for j in P]
  for j in range(M):
    for s in S[j]:
#      print(list(map(int,bin(i + 2 ** (N))[3:])),s)
      if list(map(int,bin(i + 2 ** (N))[3:]))[s - 1] == 1:
        p[j - 1] += 1
#  print(P,p,ans)
  if all([r % 2 == 0 for r in p]):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [j for j in P]
  for j in range(M):
    for s in S[j]:
#      print(list(map(int,bin(i + 2 ** (N + 1))[3:])),s)
      if list(map(int,bin(i + 2 ** (N + 1))[3:]))[s - 1] == 1:
        p[j - 1] += 1
#  print(P,p,ans)
  if all([r % 2 == 0 for r in p]):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [j for j in P]
  for j in range(M):
    for s in S[j]:
#      print(list(map(int,bin(i + 2 ** (N + 1))[3:])),s)
      if list(map(int,bin(i + 2 ** (N + 1))[3:]))[s] == 1:
        p[j - 1] += 1
#  print(P,p,ans)
  if all([r % 2 == 0 for r in p]):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [j for j in P]
  for j in range(M):
    for s in S[j]:
#      print(format(i,"0%db" % N),s)
      if format(i,"0%db" % N)[s - 1] == '1':
        p[j - 1] += 1
#  print(P,p,ans)
  if all([r % 2 == 0 for r in p]):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
K = []
S = []
P = []

for i in range(M):
  A = list(map(int,input().split()))
  K.append(A[0])
  S.append(A[1:])
P = list(map(int,input().split()))

ans = 0

for i in range(2 ** N):
  p = [0 for j in range(M)]
  for j in range(M):
    for s in S[j]:
#      print(format(i,"0%db" % N),s)
      if format(i,"0%db" % N)[s - 1] == '1':
        p[j - 1] += 1
#  print(P,p,ans)
  if all([(l == r % 2) for l,r in zip(P,p)]):
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))
ans = 0
for i in range(2 ** n):
    bag = [0]*n
    res = 0
    cnt = 0
    for j in range(n):  
        if ((i >> j) & 1):  
            bag[j]+=1
    for l in range(m):
        for h in range(1,len(x[l])):
            res += bag[x[l][h]-1]
        if res%2!=p[l]:
            break
        else:
            cnt += 1
    if cnt==m:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
connect = [0] * M
for j in range(M):
  connect_list = [int(s) for s in input().split()[1:]]
  connect[j] = sum(np.array(connect_list))
plist = list(map(int, input().split()))

count = 0
for n in range(2**N):
  for j in range(M):
    switch_on = n+1 & connect[j]
    num_switch_on = [int(k) for k in str(bin(switch_on))[2:]]
    if (sum(np.array(num_switch_on)) % 2) != plist[j]:
  		 break
    if j == M-1:
        count += 1
  
print(count)

Submission status: Wrong Answer

Solution code:
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):
    tmp=[(t>>s)&1 for s in range(N)]
    print(tmp)
    light=True
    for i in range(M):
        cnt=0
        for j in range(len(l[i])):
            if tmp[l[i][j]-1]==1:
                cnt+=1
                print(cnt)
        if cnt%2 != p[i]%2:
            light=False
    if light:
        ans+=1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def switch_on_off(n, keta):
    bin_str = format(n, '0{}b'.format(keta))
    return list(bin_str)

def check_light(n, N, s, index, P):
    switch = switch_on_off(n, N)
    sum = 0
    for v in s:
        sum += int(switch[int(v) - 1])
    if sum % 2 == P[index - 1]:
        return 1
    return 0

N, M = map(int, input().rstrip().split())
K = []
S = []
for _ in range(M):
    tmp = list(map(int, input().rstrip().split()))
    K.append(tmp[0])
    S.append(tmp[1:])
P = list(map(int, input().rstrip().split()))


ans = 0
for n in range(2 ** N):
    sum = 0
    for index, s in enumerate(S):
        sum += check_light(n, N, s, index, P)
    if sum == M:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
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):
    tmp=[(t>>s)&1 for s in range(N)]
    light=True
    for i in range(M):
        cnt=0
        for j in range(len(l[i])):
            if tmp[l[i][j]-1]=='1':
                cnt+=1
            if cnt%2!=p[i]%2:
                light=False
                break
    if light:
        ans+=1

print(ans)

Submission status: Wrong Answer

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

for i in range(2**n):
  ans += 1
  for j in range(len(s)):
    on = 0
    for k in range(s[j][0]):
      on += ((i>>s[j][k+1])%2)
    if(on%2 != p[j]):
      ans -= 1
      break
      
print(ans)

Submission status: Wrong Answer

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

for i in range(2**n):
  ans += 1
  for j in range(len(s)):
    on = 0
    for k in range(s[j][0]):
      on += (i>>(s[j][k+1])%2)
    if(on%2 != p[j]):
      ans -= 1
      break
      
print(ans)

Submission status: Wrong Answer

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

for i in range(2**n):
  ans += 1
  for j in range(len(s)):
    on = 0
    for k in range(s[j][0]):
      on += (i>>(s[j][k+1])%2)
    if(on%2 != p[j]):
      ans -= 1
      break;
      
print(ans)

Submission status: Wrong Answer

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()))

# print(S)
# print(P)

ans = 0

for i in range(1 << N):
    # print(i)
    for m in range(M):
        cnt = 0
        for s in S[m]:  # Sは繋がっているスイッチの情報
            if i & (1 << (s-1)) != 0:
                cnt += 1
        if cnt % 2 != P[m]:
            break
      # このelseはどういうこと？
        ans += 1

print(ans)

Submission status: Wrong Answer

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

for i in range(m):
    t.append(list(map(int,input().split())))
q = list(map(int,input().split()))

x = 0
import math


for switch_cond in range(2**n):
    s = []

    for i in range(n):
        if switch_cond%2 == 0:
            s.append("off")
            switch_cond = switch_cond//2
        else:
            s.append("on")
            switch_cond = (switch_cond-1)//2
    #print("s",s)
    for j in range(m):
        for r in range(n):
            if r+1 not in t[j][1:]:
                s[r]="off"
        #print("t[",j,"]",t[j][1:])
        #print("s*",s)
        if q[j]%2!=s.count("on")%2:
            #print("break!")
            break
    else:
        #print("all on!")
        x += 1
print(x)