Problem: 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?

Submission attempts (in order):
def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    # print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==1:
                OnSwitch += 1
            else:
                pass
        if OnSwitch%2==p[m]:
            Light+=1
    print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] 
Destinations=[] 
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (2**N):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==0:
                OnSwitch += 1
        if OnSwitch>0 and OnSwitch%2==p[m]:
            Light+=1
    #print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] 
Destinations=[] 
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (N**2):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    # print(SwitchPattern)
    #print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    # print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==1:
                OnSwitch += 1
            else:
                pass
        if OnSwitch%2==p[m]:
            Light+=1
    # print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] 
Destinations=[] 
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (2**N):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    # print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

Verdicts: Wrong Answer

Wrong Answer

Accepted