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:
#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 = Ture
    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)

Submission status: Runtime Error

Solution code:
import numpy as np
from itertools import product

N, M = map(int, input().split())
switch = []

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

# 剰余がこうなれば正解
p = list(map(int, input().split()))

# スイッチの状態の組み合わせを全列挙
st = list(product([0,1],repeat=N))

ans = 0

for i, s in enumerate(st):
    tmp = []
    for sw in switch:
        on = 0
        for x in sw:
            on += s[x-1]
        if (on%2)==p[m]:
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp)==True:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define MOD 1e9+7;

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector< vector<int> > ss;
    ss.resize(M);
    vector<int> p(M);
    REP(i, M) {
        int k;
        cin >> k;
        REP(j, k) {
            int s;
            cin >> s;
            --s;
            ss[i].push_back(s);
        }
    }
    REP(i, M) cin >> p[i];
    int res = 0;
    REP(S, (1<<N)) {
        bool flag = true;
        REP(j, M) {
            int m = 0;
            REP(k, (int)ss[j].size()) {
                if (S & (1<<ss[j][k])) m += 1;
            }
            if (m == 0) {
                flag = false;
                break;
            }
            if (m % 2 != p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) res += 1;
    }
    cout << res << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
from collections import deque
N,K = list(map(int,input().split()))
K = deque()
for i in range(M):
    A = deque(map(int,input().split()))
    K.append(A[0])
    A.popleft()
p = list(map(int,input().split()))
ans = 0
for i in range(1 << N):
    f = True
    for j in range(M):
        s = 0
        for k in ks[j][1:]:
            s += (i >> (k - 1)) & 1
        if s % 2 != p[j]:
            f = False
    if f:
        ans += 1
print(ans)

Submission status: Runtime Error

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

ans = 0
for b in range(1<<n):
    for i in range(m):
        c = 0
        for s in sw[i][1:]:
            if b &(1<<(s-1)):
                c += 1
        if c % 2 != p[i]:break
    else:
        ans +=1
print(ans)

Submission status: Runtime Error

Solution code:

# 解答（@maspy）

# switchが10個以下
N,M = map(int,input().split())
sw = [[] for _ in range(M)]
# print(sw) # [[], [], ..., []]

for i in range(M):
    sw[i] = list(map(int,input().split()[1:]))
# print(sw) # [[１行目], [２行目], ..., [M行目]]

import itertools

answer = 0
for tpl in itertools.product([0,1],repeat=N):
  bl = True
  for i in range(M):
    # 電球iを計算
    s = sum([tpl[s-1] for s in sw[i]])
    if (s-p[i])%2 != 0:
      bl = False
      break
  if bl:
    answer += 1
print(answer)

Submission status: Runtime Error

Solution code:
N, M = input().split()
K = []
P = []
adjacent = [[0] for i in range(M)]
for i in range(M):
  A = list(input())
  K[i] = A[0]
  adjacent[i] = A[1:]
P = list(input())
X = 0
a = [[0] for i in range(M)]
for i in range(2**N):
  b = []
  for j in range(N):
    if i%2 == 1:
      b.append(j)
    i = i//2
  for j in range(M):
    if len(set(b)&set(adjacent[j]))%2 == P[j]:
      a[j] = 1
  if sum(a) == M:
    X += 1
print(X)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    ipt = list(map(int, input().split()))
    k.append(ipt[0])
    s.append(ipt[1:])
p = list(map(int, input().split()))
cnt = 0
for sw in (list(format(i, f'0{n}b')) for i in range(2 ** n)):
    for i in range(m):
        if sum([int(sw[j - 1]) for j in s[i]]) % 2 != p[i]:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
# N:スイッチの数、M：電球の数
s = [[] for _ in range(M)]
for i in range(M):
    temp = list(map(int, input().split()))
    s[i] = temp[1:]
p = list(map(int, input().split()))
ans = 0

# bit全探索
for i in range(2 ** N):
    on = [0 for _ in range(N)]
    for j in range(N): 
        if (i >> j) & 1:
            for k in range(N):
                if j+1 in s[k]:
                    on[k] += 1
    tf = []
    for on_n, p_n in zip(on, p):
        if on_n % 2 == p_n:
            tf.append(True)
        else:
            tf.append(False)
    if all(flg for flg in tf):
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
# N:スイッチの数、M：電球の数
s = [[] for _ in range(N)]
for i in range(M):
    temp = list(map(int, input().split()))
    s[i] = temp[1:]
p = list(map(int, input().split()))
ans = 0

# bit全探索
for i in range(2 ** N):
    on = [0 for _ in range(N)]
    for j in range(N): 
        if (i >> j) & 1:
            for k in range(N):
                if j+1 in s[k]:
                    on[k] += 1
    tf = []
    for on_n, p_n in zip(on, p):
        if on_n % 2 == p_n:
            tf.append(True)
        else:
            tf.append(False)
    if all(flg for flg in tf):
        ans += 1

print(ans)

Submission status: Runtime Error

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

s_list = []
a = []
for i in range(M):
    s = list(map(int, input().split()))
    k = s[0]
    for j in range(1, k):
        a[s[j] - 1] |= 1 << i

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

p = 0
for i, x in enumerate(p):
    p |= x << i

ans = 0
for s in range(1 << N):
    t = 0
    for i in range(N):
        if s >> i & 1:
            t ^= a[i]
    if t == p:
        ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
, M = [int(x) for x in input().split()]
K = [[0]*N]*M
for i in range(M):
  K[i] = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
total = 0
for i in range(2 ** N):
    lamp = [0] * N
    for j in range(N):
        if ((i >> j) & 1):
            lamp[j] = 1
    flag = True
    for x in range(M):
      result = 0
      for y in K[x][1:]:
        if lamp[y-1] == 1:
          result += 1
      result %= 2
      if result != P[x]:
        flag = False
    if flag:
      total += 1
print(total)

Submission status: Runtime Error

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

for i in range(2 ** n):
    for m in range(M):
        switch = 0
        for j in range(n):
            if (i >> j) & 1:
                if j + 1 in s[m]:
                    switch += 1
        if switch % 2 != p[m]:
            break
    else:
        count += 1
print(count)

Submission status: Runtime Error

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

for i in range(2 ** N):
  sw = [0]*N
  for j in range(N):
    if ((i >> j) & 1):
      sw[j] = 1
  frg = True
  for j in range(M):
    a = ks[j][0]
    aa = 0
    for k in range(a):
      aa += sw[k+1]
    if aa%2 != p[j]:
      frg = False
  if frg:
    c += 1
    
print(c)

Submission status: Runtime Error

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

ans = 0
for i in range(1<<n):
  flag = True
  for i in range(m):
    l = light[m][1:]
    count = 0
    for s in l:
      if i & (1<<(s-1)):
        count += 1
    if count%2 != p[m]:
      flag = False
  if flag==True:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
slist = [list(map(int, input().split()))[1:] for _ in range(M)]
plist = list(map(int, input().split()))

def count_on_switch(switch_array: list, on: set):
    return sum([int(sw in on) for sw in switch_array])

ans: int = 0
# print("---")
for i in range(2**N):
    on = set()
    for j in range(N):
        if ((i >> j) & 1):
             on.add(j+1)
    temp = 0
    for _ in range(M):
        cou_on = count_on_switch(slist[_], on)
        # print(i, cou_on)
        if cou_on % 2 != plist[_]:
            break
    else:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
Not found

Submission status: Runtime Error

Solution code:
M = map(int,input().split()) #N:スイッチ　＃M：電球
#print(N)

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


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

ans = 0
for i in range(2**N):
    #print("num {}" .format(i), end="")
    sw = [0]*N
    for j in range(N):
        if ((i >>j) & True):
            sw[j]=1

    else:
        pass
        #print(sw)

    #Ans =[]
    On_Light_nmb = 0
    for m in range(M): #電球ごとに判定
        sum = 0
        for k in range(light[m][0]):
            s_nmb = int(light[m][k+1])
            #print(s_nmb)
            #print(sw[s_nmb-1])
            sum += sw[s_nmb-1]

        if sum%2 == p[m]: #電球mのOnスイッチの合計が
            #Ans.append(1)
            On_Light_nmb +=1
            #print('light '+str(m)+' on')
        else:
            pass
            #Ans.append(0)
            #print('light '+str(m)+' off')

    #print('ans:'+str(ans))

    #もしすべてのライトがついていたら
    if On_Light_nmb == m+1:
        ans +=1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

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


def switch(bit, ans):
    check = [(bit >> i) & 1 for i in range(N)]
    light = 0
    for i in range(M):
        num = 0
        for l in s[i]:
            if check[l - 1] == 1:
                num += 1
        if num % 2 == p[i]:
            light += 1
    if light == M:
        ans += 1
    if bit == 1:
        return ans
    else:
        return switch(bit - 1, ans)


print(switch(2 ** N, 0))

Submission status: Runtime Error

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

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


def switch(bit, ans):
    check = [(bit >> i) & 1 for i in range(N)]
    light = 0
    for i in range(M):
        num = 0
        for l in s[i]:
            if check[l - 1] == 1:
                num += 1
        if num % 2 == p[i]:
            light += 1
    if light == M:
        ans += 1
    if bit == 1:
        print(ans)
    else:
        switch(bit - 1, ans)


switch(2 ** N, 0)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
l=[]
for i in range(M):
    L = list(input().split())
    l.append(l[1:]) 
s=list(input().split())
c=0
for i in range(2**N):
    for j in range(M):
        a = 0
        for k range(N):
            if ((i >>k) == 1 and k+1 in l[j]:
                a += 1
        if a%2 == s[j]:
            d *= 1
        else:
            d *= 0
    if d == 1:
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
k = []
s = []
for _ in range(M):
    std_in = list(map(int, input().split()))
    k.append(std_in[0])
    for i in range(std_in[0]):
        std_in[i+1] -= 1
    s.append(std_in[1:])
p = [int(i) for i in input().split()]

switches = [0] * N

def judge_bulbs(switches):
    for i in range(M):

        k_sum = 0
        for ki in range(k[i]):
            k_sum += switches[ki]

        if k_sum % 2 == p[i]:
            continue
        else:
            return False
    return True

def solve(idx, switches):
    if idx == N:
        if judge_bulbs(switches):
            return 1
        else:
            return 0

    ans = 0
    switches = switches.copy()
    
    ans += solve(idx+1, switches)

    switches[idx] = 1
    ans += solve(idx+1, switches)
    return ans

print(solve(0, switches))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M= list(map(int, input().split()))
K = []
S=[]
state_S = np.zeros(N)
for m  in range(M):
    _input = list(map(int, input().split()))
    K.append(_input[0])
    S.append(np.array(_input[1:]))
P = list(map(int, input().split()))
ans=0
for i in range(N ** 2):
    pattern= np.array([i >> bit & 1 for bit in range(N)])
    if all(sum(pattern[K[j] -1 ]) % 2 == P[j] for j in range(M)):
        ans += 1
print(ans)

Submission status: Runtime Error

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

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

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        SUM = 0
        for k in switches[j]:
            SUM += int(i[k-1])
        if SUM%2 != R[j]:
            flag = 1
    if flag == 0:
        ans += 1

print(ans)

Submission status: Runtime Error

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

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

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        sum = 0
        for k in switches[j]:
            sum += int(i[k-1])
        if sum%2 != R[j]:
            flag = 1
    if flag == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

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

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

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

a = [list(f"{i:0{N}b}") for i in range(2**N)]

ans = 0

for i in a:
    flag = 0
    for j in range(M):
        sum = 0
        for k in switches[j]:
            sum += int(i[k-1])
        if sum%2 != R[j]:
             flag = 1
    if flag == 0:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def judgeAllBulbsOn(switchOn, conds, p):
  m = len(conds)
  flag = True
  for i in range(m):
    k = conds[i][0]
    numOfBulbOn = 0
    for i in range(k):
      if switchOn[conds[i][k]] == True:
        numOfBulbOn +=1
    if numOfBulbOn % 2 != p[m]:
      flag = False
      break
  return flag
      

#n:switch, m:bulb
n, m = map(int, input().split())

conds = []
for i in range(m):
  connect = list(map(int, input().split()))
  conds.append(connect)
  
p = list(map(int, input().split()))

switchOn = [False]*n

ans = 0
for bit in range(1<<n):
  for i in range(n):
    if bit & 1<<i == 1:
      switchOn[i] = True
    else:
      switchOn[i] = False
  if judgeAllBulbsOn(switchOn, conds, p):
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
import itertools

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

sw = [[] for _ in range(M)]
for i in range(m):
    sw[i] = list(map(int,input().split()[1:])) #k不要
     
p = list(map(int,input().split()))

res = 0
for tpl in itertools.product([0,1],repeat=n):
    bl = True
    for i in range(m):
        s = sum([tpl[s-1] for s in sw[i]]) # 電球iを計算
        if (s-p[i])%2 != 0:
            bl = False
            break
    if bl:
        res += 1
print(res)

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()))
total = 0
j = 0
for i in range(2 ** N):
  now = format(i, '10b')
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += int(now[-l])
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
def main():
    n, m = map(int, input().split())
    switch_list = [list(map(int, input().split())) for _ in range(m)]
    p = list(map(int, input().split()))
    ret = 0
    for j in range(2**n):
        cnt = 0
        for i in range(m):
            flag = 1
            for k in switch_list[i][1:]:
                if j & 2**(k-1):
                    total += 1
            if not total%2 == p[i]:
                flag = 0
                break
        if flag:
            ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) for i in range(M)]
p = list(map(int, input().split()))
total = 0
flag = 1
for i in range(2 ** N):
  now = format(i, "0{}b".format(N))
  for k in range(M):
    tmp = 0
    for l in range(s[k][0]):
      if now[s[k][l+1]-1] == '1':
        tmp += 1
    if tmp % 2 == p[k]:
      continue
    else:
      flag = 0
      break
  if flag == 1:
    total += 1
  flag = 1
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) for i in range(M)]
p = list(map(int, input().split()))
total = 0
flag = 1
for i in range(2 ** N):
  now = format(i, "0{}b".format(n))
  for k in range(M):
    tmp = 0
    for l in range(s[k][0]):
      if now[s[k][l+1]-1] == '1':
        tmp += 1
    if tmp % 2 == p[k]:
      continue
    else:
      flag = 0
      break
  if flag == 1:
    total += 1
  flag = 1
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) for i in range(M)]
p = list(map(int, input().split()))
total = 0
flag = 1
for i in range(2 ** N):
  now = format(i, "0{}b".format(n))
  for k in range(M):
    tmp = 0
    for l in range(s[k][0]):
      if now[s[k][l+1]-1] == '1':
        tmp += 1
    if tmp % 2 == p[k]:
      continue
    else:
      flag = 0
      break
  if flag == 1
    total += 1
  flag = 1
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) for i in range(M)]
p = list(map(int, input().split()))
total = 0
flag = 1
for i in range(2 ** N):
  now = format(i, '010b')
  for k in range(M):
    tmp = 0
    for l in range(s[k][0]):
      if now[-s[k][l+1]] == '1':
        tmp += 1
    if tmp % 2 == p[k]:
      continue
    else:
      flag = 0
      break
  if flag == 1
    total += 1
  flag = 1
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit()))[1:] for i in range(M)]
p = list(map(int, input().split()))
total = 0
j = 0
for i in range(2 ** N):
  now = format(i, '010b')
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += int(now[-l])
    if tmp % 2 == p[k]:
      j += 1
  if j == M:
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit()))[1:] for i in range(M)]
p = list(map(int, input().split()))
total = 0
j = 0
for i in range(2 ** N):
  now = format(i, '10b')
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += int(now[-l])
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) [1:] for i in range(M)]
p = list(map(int, input().split()))
total = 0
j = 0
for i in range(2 ** N):
  now = format(i, '10b')
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += int(now[-l])
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) [1:] for i in range(M)]
p = list(map(int, input().split()))
total = 0
j = 0
for i in range(2 ** N):
  now = format(i, 'Nb')
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += int(now[l-1])
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int, input().spllit())) [1:] for i in range(M)]
p = list(map(int, input().split()))
total = 0
j = 0
for i in range(2 ** N):
  lis = []
  for j in range(N):
    lis.append((i>>j) & 1)
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += lis[l-1]
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int,input().spllit()))[1:] for i in range(M)]
p = list(map(int,input().split()))
total = 0
j = 0
for i in range(2 ** N):
  lis = []
  for j in range(N):
    lis.append((i>>j) & 1)
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += lis[l-1]
    if tmp % 2 == p[k]:
      j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
s = [list(map(int,input().spllit()))[1:] for i in range(M)]
p = list(map(int,input().split()))
total = 0
j = 0
for i in range(2 ** N):
  lis = []
  for j in range(N):
    lis.append((i>>j) & 1)
  for k in range(M):
    tmp = 0
    for l in s[k]:
      tmp += lis[l-1]
      if tmp % 2 == p[k]:
        j += 1
  if j == M :
    total += 1
  j = 0
print(total)

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

ans = 0
N,M = map(int,readline().split())
L = []

for i in range(M):
    k,*S = map(int,readline().split())
    L.append(S)

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

A = list(itertools.product([0,1],repeat=N))

for i in A:
    sw = [False] * N
    for j in range(M):
        count = 0
        for k in L[j]:
            count += i[k-1]

        if count % 2 == P[j]:
            sw[j] = True
            
    if sum(sw) == N:
        ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
ss = []
for _ in range(m):
  s = list(map(int,input().split()))[1:]
  ss.append()
ps = list(map(int,input().split()))

def get_bit(i,n):
  res = []
  for i in range(n):
    res.append(i%2)
    i = int(i/2)
  return res[::-1]

ans = 0
for i in range(2**n):
  flags = get_bit(i,n)
  for j in range(m):
    count = 0
    for k in ss[j]:
      count += flags[k-1]
    if count %2 == ps[j]:
      continue
    else:
      break
  else:
    ans += 1
print(ans)

Submission status: Runtime Error

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

for i in range(2**n):
    ptn = format(i, 'b').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:
        res += 1
print(res)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
s_lst = [list(map(int,input().split())) for i in range(m)]
k_lst = []
for i in range(m):
    k = s_lst.pop(s_lst[i][0])
    k_lst.append(k)
p_lst = list(map(int,input().split()))
answer = 0

for i in range(2**n): #各電球がonかoffかビット全探索
    on_lst =[0]*n
    flag = True
    for j in range(n):
        if (i>>j) & 1:
            on_lst[j] = 1
    for l in range(m): ##　一つ一つの電球について確認
        number = 0
        s = s_lst[l]
        for sw in s:
            if on_lst[sw-1]==1:
                number += 1
        if number%2 != p[i]:
            flag = False
            break
    if flag:
        answer += 1

print(answer)

Submission status: Runtime Error

Solution code:
satoooh
N, M = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(M)]  #sの各要素のはじめはk
p = list(map(int, input().split()))
ans = 0

# 0をoffとして2進数でパターンを表現

for i in range(2 ** N):
	ptn = bin(i)[2:].rjust(N, "0")  # N桁の2進表現にする
	light = True  # 着目している電球が点灯していないときはこれがFalseになる
	for j in range(M):
		tmp = 0  # 着目している電球について、スイッチのonの個数をカウントする
		for n in range(1, s[j][0] + 1):
			if ptn[s[j][n] - 1] == "1":
				tmp += 1
		if tmp % 2 != p[j] % 2:
			light = False
	if light:
		ans += 1

print(ans)

Submission status: Runtime Error

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

ans = 0

for bit in range(1 << N):
    flag = True
    for i in range(N):
        count = 0
        for v in ks[i]:
            if bit & (1<<(v-1)):
                cnt += 1
        if cnt %2 != p[i]:
            flag = False
    if flag:
        ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
light = []
for _ in range(m):
  s_map = map(int, input().split())
  next(s_map)
  indices = [s-1 for s in s_map]
  light.append(int('0b' + ''.join(number)))
p = list(map(int, input().split()))
count = 0
for i in range(1 << n):
  list_i = [int(bit) for bit in format(i, '0{}b'.format(n))]
  flag = True
  for j in range(m):
    on = 0
    for idx in indices:
      on ^= list_i[idx]
    if on != p[j]:
      flag = False
      break
  if flag:
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
rom itertools import product
 
n, m = map(int, input().split())
k = []
s = []
for i in range(m):
    tmp = list(map(int, input().split()))
    k.append(tmp[0])
    s.append(tmp[1:])
p = list(map(int, input().split()))
 
ans = 2 ** n
for prod in (product([0, 1], repeat=n)):
    for i in range(m):
        tmp = 0
        for j in s[i]:
            tmp += prod[j - 1]
        if (tmp % 2 != p[i]):
            ans -= 1
            break
print(ans)

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()))
form = "0"+str(n)+"b"
ans = 0
for i in range(2**n):
    ptn = format(i,form)
    light = True
    for j in range(m):
        s = sum(int(ptn[k-1])for k in s[j])
        if s%2 != p[j]:
            light = False
    if light == True:
        ans += 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)]
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 k in range(1,s[j][0]+1):
            if ptn[s[j][n]-1] == "1":
                tmp += 1
        if tmp % 2 != p[j]% 2:
            light = False
    if light:
        ans += 1
print(ans)