AtCoder Beginner Contest 128 C – Switches

AtCoderなど過去問

AtCoder Beginner Contest 128 C – Switches

from itertools import product

n,m = map(int,input().split())
light = []


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

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

cnt = 0
for pro in product((0,1), repeat = n):
    ok = True
    for i in range(m):
        if not ok:
            break
        s = 0
        for ind,j in enumerate(light[i]):
            if not ind:
                continue
            s += pro[j-1]
        if s % 2 != p[i]:
            ok = False
            break
    if ok:
        cnt += 1
                
print(cnt)

コメント

タイトルとURLをコピーしました