Problem:


Score : 300 points

Problem Statement

There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.

Person i gives A_i testimonies. The j-th testimony by Person i is represented by two integers x_{ij} and y_{ij}. If y_{ij} = 1, the testimony says Person x_{ij} is honest; if y_{ij} = 0, it says Person x_{ij} is unkind.

How many honest persons can be among those N people at most?

Constraints

All values in input are integers.

1 \leq N \leq 15

0 \leq A_i \leq N - 1

1 \leq x_{ij} \leq N

x_{ij} \neq i

x_{ij_1} \neq x_{ij_2} (j_1 \neq j_2)

y_{ij} = 0, 1

Input

Input is given from Standard Input in the following format:

N
A_1
x_{11} y_{11}
x_{12} y_{12}
:
x_{1A_1} y_{1A_1}
A_2
x_{21} y_{21}
x_{22} y_{22}
:
x_{2A_2} y_{2A_2}
:
A_N
x_{N1} y_{N1}
x_{N2} y_{N2}
:
x_{NA_N} y_{NA_N}

Output

Print the maximum possible number of honest persons among the N people.

Sample Input 1

3
1
2 1
1
1 1
1
2 0

Sample Output 1

2

If Person 1 and Person 2 are honest and Person 3 is unkind, we have two honest persons without inconsistencies, which is the maximum possible number of honest persons.

Sample Input 2

3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0

Sample Output 2

0

Assuming that one or more of them are honest immediately leads to a contradiction.

Sample Input 3

2
1
2 0
1
1 0

Sample Output 3

1



Sample input:
3
1
2 1
1
1 1
1
2 0


Sample output:
2

Submission status: Wrong Answer

Solution code:
from itertools import product
import copy
N = int(input())
A = [[-1 for _ in range(N+1)] for _ in range(N+1)]
for i in range(1,N+1):
    k = int(input())
    for j in range(k):
        x,y = map(int,input().split())
        A[i][x] = y
cmax = 0
for z in product((0,1),repeat=N):
    B = copy.deepcopy(A)
    for i in range(N):
        if z[i]==0:
            for j in range(1,N+1):
                if B[i+1][j]!=-1:
                    B[i+1][j] = 1-B[i+1][j]
            B[i+1][i+1] = 0
        else:
            B[i+1][i+1] = 1
    flag = 0
    for j in range(1,N+1):
        c0 = 0
        c1 = 0
        for i in range(1,N+1):
            if B[i][j]==0:
                c0 += 1
            elif B[i][j]==1:
                c1 += 1
        if c0>0 and c1>0:
            flag = 1
            break
    if flag==0:
        cmax = max(cmax,sum(z))
print(cmax)

Submission status: Wrong Answer

Solution code:
from itertools import product
import copy
N = int(input())
A = [[-1 for _ in range(N+1)] for _ in range(N+1)]
for i in range(1,N+1):
    k = int(input())
    for j in range(k):
        x,y = map(int,input().split())
        A[i][x] = y
cmax = 0
for z in product((0,1),repeat=N):
    B = copy.deepcopy(A)
    for i in range(N):
        if z[i]==0:
            for j in range(1,N+1):
                if B[i+1][j]!=-1:
                    B[i+1][j] = 1-B[i+1][j]
    flag = 0
    for j in range(1,N+1):
        c0 = 0
        c1 = 0
        for i in range(1,N+1):
            if B[i][j]==0:
                c0 += 1
            elif B[i][j]==1:
                c1 += 1
        if c0>0 and c1>0:
            flag = 1
            break
    if flag==0:
        cmax = max(cmax,sum(z))
print(cmax)

Submission status: Wrong Answer

Solution code:
n=int(input())
xy=[[]for _ in range(n)]
for i in range(n):
  for j in range(int(input())):
    xy[i].append(list(map(int,input().split())))
ans=0
for i in range(1,1<<n):
  syojiki=[(i&(1<<j)!=0)+0 for j in range(n)]
  flag=True
  for j in range(n):
    for x,y in xy[j]:
      if syojiki[x-1]!=y^syojiki[j]^1:flag=False
  if flag:
    ans=max(ans,syojiki.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
#標準入力受け取り
N = int(input())
shougen = []
A_lis = []
for _ in range(N):
    A = int(input())
    A_lis.append(A)
    minishougen = []
    for j in range(A):
        xy = list(map(int, input().split()))
        minishougen.append(xy)
    shougen.append(minishougen)

#ビットの配列作る
bit_lis = []
for i in range(2 ** N):
    mini_bit_lis = []
    for j in range(N):
        mini_bit_lis.append(i % 2)
        i = i // 2
    bit_lis.append(mini_bit_lis)
    
#ビットの配列について全探索を行う
ans = 0
for i in range(2 ** N):
    flag = 0
    for l in range(N):
        if bit_lis[i][l] == 1:
            for k in range(A_lis[j]): 
                if shougen[j][k][1] != bit_lis[i][shougen[j][k][0] - 1]:
                    flag = 1
                    break
        if flag == 1:
            break
    if flag == 0:
        tmp = sum(bit_lis[i])
        if tmp > ans :
            ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
X=[]
Y=[]
for n in range(N):
    A=int(input())
    lx=[]
    ly=[]
    for m in range(A):
        x,y=map(int,input().strip().split())
        lx.append(x)
        ly.append(y)
    X.append(lx)
    Y.append(ly)    

def judge(l,X,Y):
    honest=True
    for n in range(N):
        if l[n]==1:
            for i in range(len(X[n])):
                if l[X[n][i]-1]!=Y[n][i]:
                    honest=False
    return honest

ans=0
def dfs(l,N): #honest=1,unkind=0
    if len(l)==N:
        global ans
        if judge(l,X,Y):
            ans=max(ans,sum(l))
            return
    else:
        for n in range(2):
            l.append(n)
            print(l)
            dfs(l,N)
            l.pop()

dfs([],N)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

talk=[]

for _ in range(n):
    a=int(input())
    sei=set([])
    uso=set([])
    for __ in range(a):
        x,y=map(int,input().split())
        if y==1:
            sei.add(x-1)
        else:
            uso.add(x-1)
    
    talk.append((sei,uso))
#print(talk)
result=0
for i in range(2**n):
    #print(bin(i))
    flag=0
    s=str(bin(i))[2:].zfill(n)
    #print("#####",s)
    kari_sei=set([])
    kari_uso=set([])

    for j in range(n):
        if i>>j &1:
            kari_sei.add(j)
        else:
            kari_uso.add(j)

    flag=0
    for item in kari_sei:
        for item2 in talk[item-1][0]:
            if item2 not in kari_sei:
                flag=1
                break
        if flag==1:
            break
        else:
            for item2 in talk[item-1][1]:
                if item2 not in kari_uso:
                    flag=1
                    break
            
    
    if flag==0:
        result=max(result,s.count("1"))

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())

talk=[]

for _ in range(n):
    a=int(input())
    sei=set([])
    uso=set([])
    for __ in range(a):
        x,y=map(int,input().split())
        if y==1:
            sei.add(x)
        else:
            uso.add(x)
    
    talk.append((sei,uso))
#print(talk)
result=0
for i in range(2**n):
    flag=0
    s=str(bin(i))[2:].zfill(n)
    #print("#####",s)
    kari_sei=set([])
    kari_uso=set([])

    for j in range(n):
        if i>>j &1:
            kari_sei.add(j)
        else:
            kari_uso.add(j)

    flag=0
    for item in kari_sei:
        for item2 in talk[item-1][0]:
            if item2 not in kari_sei:
                flag=1
                break
        if flag==1:
            break
        else:
            for item2 in talk[item-1][1]:
                if item2 not in kari_uso:
                    flag=1
                    break
            
    
    if flag==0:
        result=max(result,s.count("1"))

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())

talk=[]

for _ in range(n):
    a=int(input())
    temp=[]
    for __ in range(a):
        x,y=map(int,input().split())
        temp.append((x,y))
    
    talk.append(temp)
#print(talk)
result=0
for i in range(2**n):
    flag=0
    s=str(bin(i))[2:].zfill(n)
    #print("#####",s)
    for j in range(n):
        if i>>j &1:
            temp=talk[j]
            #print(j)
            for item in temp:
                xx=item[0]-1
                yy=item[1]
                
                #if s=="011":
                #    print(xx,yy,n-xx-1,s)

                if s[n-xx-1]!=str(y):
                    flag=1
    
    if flag==0:
        result=max(result,s.count("1"))

print(result)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
lists = deque()
A = deque() 
ans = 0
for _ in range(n):
    a = int(input())
    A.append(a)
    tmp = [list(map(int, input().split())) for _ in range(a)]
    lists.append(tmp)
def judge(bit):
    for i in range(n):
        if ((bit>>i)&1) == 0:
            continue
        for j in range(A[i]):
            x,y = lists[i][j]
            x -= 1

            if y==1 and ((bit>>i)&1 == 0):
                return False
            if y==0 and ((bit>>i)&1 == 1):
                return False
    else:
        return True

for bit in range(1<<n):
    if judge(bit):
        cnt = 0
        for k in range(n):
            if (bit>>k)&1:
                cnt += 1
        ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
lists = deque()
A = deque() 
ans = 0
for _ in range(n):
    a = int(input())
    A.append(a)
    tmp = [list(map(int, input().split())) for _ in range(a)]
    lists.append(tmp)

for bit in range(1<<n):
    flag = True
    is_honest = [(bit>>i)&1 for i in range(n)]
    print(is_honest)
    for i in range(n):#i人目の証言を検証する
        if is_honest[i] == 0:#i人目が「不親切」ならその人の証言は無視
            continue
        for k in range(A[i]):#i人目のk個目の証言を検証する
            x,y = lists[i][k]
            x -= 1
            #番号xとyが一致しているかどうか
            if is_honest[x] != y:
                flag = False
    if flag:
        ans = max(ans, sum(is_honest))
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
n = int(input())
lists = deque()
A = deque() 
ans = 0
for _ in range(n):
    a = int(input())
    A.append(a)
    tmp = [list(map(int, input().split())) for _ in range(a)]
    lists.append(tmp)
def judge(bit):
    for i in range(n):
        if (bit&(a<<i)) == 0:
            continue
        for j in range(A[i]):
            x,y = lists[i][j]

            if y==1 and (bit&(1<<x)) == 0:
                return False
            if y==0 and (bit&(1<<x)) == 1:
                return False
    return True

for bit in range(1<<n):
    if judge(bit):
        cnt = 0
        for k in range(n):
            if bit&(1<<k):
                cnt += 1
        ans = max(ans, cnt)
print(ans-1)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())

A = []
xy = []
for _ in range(N):
    a = int(input())
    A.append(a)
    for _ in range(a):
        xy.append(list(map(int, input().split())))

ans = 0
for hu in list(itertools.product([0,1], repeat=N)):
    xy_idx = 0
    ok_flg = 1
    for i in range(N):
        if hu[i]:
            for _ in range(A[i]):
                x, y = xy[xy_idx]
                x -= 1
                if hu[x] != y:
                    ok_flg = 0
                    break
                xy_idx += 1
        else:
            for _ in range(A[i]):
                x, y = xy[xy_idx]
                x -= 1
                if hu[x] == y:
                    ok_flg = 0
                    break
                xy_idx += 1
    if ok_flg:
        ans = max(ans, sum(hu))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

d = {}
for i in range(N):
    a = int(input())
    xy = []
    for j in range(a):
        s = list(map(int, input().split()))
        xy.append(s)
    d[i+1] = xy

max = 0
for i in range(2**N):
    #print()
    switch = []
    for j in range(N):
        if ((i >> j) & 1):
            switch.append(j+1)
    #print("switch", switch)
    
    count = 0
    for j in switch:
        for k in d[j]:
            #print(k)
            if (k[1] == 1) and (k[0] not in switch):
                #print(str(j) + "は不親切な人")
                count = 0
                break
            elif (k[1] == 1) and (k[0] in switch):
                #print(str(j) + "は正直者")
                count += 1
            elif (k[1] == 0) and (k[0] in switch):
                #print(str(j) + "は不親切な人")
                count = 0
                break
            elif (k[1] == 0) and (k[0] not in switch):
                #print(str(j) + "は正直者")
                count += 1
        if count == 0:
            break
                
    #print("正直者は" + str(count) + "人")
    
    if max < count:
        max = count

print(max)

Submission status: Wrong Answer

Solution code:
N=int(input())

A=[]
test = []
for i in range(N):
    A_i= int(input())
    A.append(A_i)
    testimony_i=[]
    for j in range(A_i):
        x,y= map(int,input().split())

        testimony_i.append([x,y])
    
    test.append(testimony_i)

print(A)
print(test)


total=0

for i in range(2**N):

    member = format(i,'0{}b'.format(N))

    print(member)
    flg = 0

    for j in range(N):
        if member[j]== '1':

            syogen = test[j]

            for s in syogen:
                if member[s[0]-1]==str(s[1]):
                    continue
                else:
                    flg+=1

    if flg ==0:
        total = max(total , member.count('1')) 

print(total)
# total = 0
# for i in range(2**N):
    
#     Honests=[0]*N
    
#     for j in range(N):

#         if (i>>j) & 1:

#             A_j = A[j]
            
#             for k in range(A_j):
#                 x,y =test[j][k][0],test[j][k][1]

#                 x-=1
#                 if y ==1:
#                     Honests[x]=1
#                 else:
#                     Honests[x]=0
#         else:
#             A_j=A[j]

#             for k in range(A_j):
#                 x,y =test[j][k][0],test[j][k][1]

#                 x-=1
#                 if y ==1:
#                     Honests[x]=0
#                 else:
#                     Honests[x]=1
            
#     total = max(total,max(Honests))

# print(total)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from itertools import product

N = int(input())
info = []

for i in range(N):
    for _ in range(int(input())):
        x, y = map(int, input().split())
        info.append((i, x-1, y))

whole = np.array(list(product([0,1],repeat=N)), np.bool)

for i, x, y in info:
    b = (whole[:, i] & whole[:, x]==y) | (~whole[:, i] & whole[:, x] != y)
    whole = whole[b]

print(whole.sum(axis=1).max())

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
L=[]
for i in range(n):
    a=int(input())
    A.append(a)
    L.append([])
    for j in range(a):
        L[i].append(list(map(int,input().split())))
    
ans=0

for i in range(2*n):
    l=[]
    m=i
    for j in range(n):
        l.append(m%2)
        m=m//2
    flag=True
    cnt=0
    for k in range(n):
        if l[k]==1:
            cnt+=1
            for a in range(A[k]):
                if L[k][a][1]!=l[L[k][a][0]-1]:
                    flag=False
    if flag:
        ans=max(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import product
n = int(input())
testimony = []
cand = []

for i in range(n):
    a = int(input())
    t = [list(map(int, input().split())) for _ in range(a)]
    testimony.append(t)

for bits in product(range(2), repeat=n):
    pattern = [[0,0] for _ in range(n)]
    for num, bit in enumerate(bits):
        for t in testimony[num]:
            if not(t[1] ^ bit):
                pattern[t[0]-1][1] += 1
            elif t[1] ^ bit:
                pattern[t[0]-1][0] += 1
    # print(bits, list(filter(lambda x: x[1] * x[0] == 0, pattern)))
    if len(list(filter(lambda x: x[1] * x[0] == 0, pattern))) == n: # test contradition
        truther = 0
        for num, bit in enumerate(bits):
            if pattern[num][1]:
                if bit:
                    truther += 1

        cand.append(truther)

print(max(cand) if cand else 0)

Submission status: Wrong Answer

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

    
kouho=[]
for i in range(0,2**n):
  liis=[]
  for j in range(0,n):
    j=n-j-1
    onezero=i//(2**j)
    liis.append(onezero)
    i-=onezero*(2**j)
  kouho.append(liis)

maxx=0
for i in range(0,2**n):
  keep=0
  for j in range(0,n):
    usohonto=kouho[i][j]
    for k in range(0,len(lis[j])):
      shoge_hito=lis[j][k][0]
      shoge_data=lis[j][k][1]
      if usohonto==1:
        if not kouho[i][shoge_hito-1]==shoge_data:
          keep=1
          break
      else:
        if kouho[i][shoge_hito-1]==shoge_data:
          keep=1
          break
  if keep==0:
    temp=kouho[i].count(1)
    if temp>maxx:
      maxx=temp
print(maxx)

Submission status: Wrong Answer

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

    
kouho=[]
for i in range(0,2**n):
  liis=[]
  for j in range(0,n):
    j=n-j-1
    onezero=i//(2**j)
    liis.append(onezero)
    i-=onezero*(2**j)
  kouho.append(liis)
maxx=0
for i in range(0,2**n):
  keep=0
  for j in range(0,n):
    usohonto=kouho[i][j]
    for k in range(0,len(lis[j])):
      shoge_hito=lis[j][k][0]
      shoge_data=lis[j][k][1]
      if usohonto==1:
        if kouho[i][shoge_hito-1]!=shoge_data:
          keep=1
          break
      else:
        if kouho[i][shoge_hito-1]==shoge_data:
          keep=1
          break
    if keep==1:
      break
  if keep==0:
    temp=kouho[i].count(1)
    if temp>maxx:
      maxx=temp
print(maxx)

Submission status: Wrong Answer

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

import itertools
from collections import deque

n = int(input())

xy = []
for i in range(n):
    a = int(input())
    xy.append([list(map(int, input().split())) for _ in range(a)])

ans = 0
for i in itertools.product([0, 1], repeat=n):
    honest_list = [-1]*n
    flag = 0

    queue_list = [i for i, x in enumerate(i) if x == 1]
    if len(queue_list) != 0:
        d = deque(queue_list)

        while(len(d) != 0):
            index = d.pop()

            xy_tmp = xy[index]
            for k in range(len(xy_tmp)):
                x, y = xy_tmp[k]

                if y == 1:
                    if honest_list[x-1] == 0:
                        flag = 1
                        break
                    elif honest_list[x-1] == -1:
                        d.append(x-1)

                if honest_list[x-1] != -1:
                    if honest_list[x-1] != y:
                        flag = 1
                        break
                    else:
                        honest_list[x-1] = y
                else:
                    honest_list[x-1] = y

            if flag == 1:
                break
    if flag == 1:
        ans_tmp = 0
    else:
        ans_tmp = len([i for i in honest_list if i == 1])

    ans = max(ans, ans_tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
xy = []
max = 0
for i in range(n):
  a = int(input())
  A.append(a)
  xy.append([list(map(int,input().split())) for i in range(a)])
for i in range(2**n):
    ls = [-1]*n
    check = 0
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = 1
    for p in range(len(xy)):
      for t in xy[p]:
        if t[1] == 1:
          if ls[t[0]-1] != ls[p]:
            check = 1
        else:
          if ls[t[0]-1] != -ls[p]:
            check = 1
    if check == 0:
      if ls.count(1) > max:
        max = ls.count(1)
print(max)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
xy = []
max = 0
for i in range(n):
  a = int(input())
  A.append(a)
  xy.append([list(map(int,input().split())) for i in range(a)])
for i in range(2**n):
    ls = [-1]*n
    check = 0
    for j in range(len(ls)):
        if (i >> j) & 1:
            ls[j] = 1
    for p in range(len(xy)):
      for t in xy[p]:
        if t[1] == 1:
          if ls[t[0]-1] != ls[p]:
            check = 1
            break
        else:
          if ls[t[0]-1] != -ls[p]:
            check = 1
            break
    if check == 0:
      if ls.count(1) > max:
        max = ls.count(1)
print(max)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    ans = []
    for _ in range(n):
        a_num = int(input())
        t = []
        for _ in range(a_num):
            t.append(tuple(map(int, input().split())))
        t = tuple(t)
        ans.append(t)

    #　BIT全探索で全パターンを回し、矛盾のないパターン数を数える。
    # 矛盾あるなし判定は、正直者の証言のみ見る。証言内容がパターンと一致しているなら矛盾なし。
    r = 0
    for bit in range(1 << n):
        honest = []
        for i1 in range(n):
            mask = 1<<i1
            if bit & mask:
                honest.append(i1)

        flag = 1
        if not honest:
            flag = 0
        for eh in honest:
            say = ans[eh]
            for esay in say:
                if esay[0] - 1 in honest:
                    if not esay[1]:
                        flag = 0
                else:
                    if esay[1]:
                        flag = 0
        r += flag
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

# print("")
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
    array = [-1] * N
    testimony_list.append(array)
for i in range(N):
    A = int(input())
    for j in range(A):
        # iさんの、xさんへの証言
        x, y = map(int, input().split())
        # print("test:{} {}".format(x, y))
        # iさんの、xさんへの証言
        # print("test:{} {} {}".format(x - 1, i, y))
        # print(testimony_list)
        testimony_list[i][x - 1] = y

# print(testimony_list)
max_count = 0
failed = False
for i in range(2 ** N):
    results = [-1] * N
    for j in range(len(testimony_list)):
        # check = (i >> j & 1)
        # print("チェック: {} {}".format(i, j))
        # print(i >> j & 1)
        if i >> j & 1:
            # print("{}:{}".format(bin(i), j))
            array = testimony_list[j]
            for k in range(len(array)):
                # print(
                #     "k={} result[k]:array[k] {}:{}".format(
                #         k, results[k], array[k]))
                # print(i >> k & 1)
                if not (i >> k & 1) and array[k] == 1:
                    # print("矛盾2")
                    failed = True
                    break
                elif (i >> k & 1) and array[k] == 0:
                    # print("矛盾3")
                    failed = True
                    break
                if array[k] == -1:
                    continue
                if results[k] == -1:
                    results[k] = array[k]
                elif results[k] != array[k]:
                    # print("矛盾1")
                    failed = True
                    break
        if failed is True:
            # print("failed")
            # results = [-1] * N
            break
    if failed is True:
        failed = False
        continue
    # print("計算: {}".format(i))
    # print(results)
    count = 0
    for result in results:
        if result != -1:
            count += 1
    # print(count)
    if max_count < count:
        max_count = count
print(max_count)

Submission status: Wrong Answer

Solution code:

N = int(input())
#二次元配列
A = []

for i in range(N):
    a = int(input())
    #A.append([])
    for j in range(N):
        A.append([0]*N)
    for j in range(a):
        x,y = map(int, input().split())
        #A[i].append([x-1,y])
        A[i][x-1] = y

ans = 0
for i in range(2**N):
    #1:本当 0:嘘
    lie = [1]*N
    flg = 0
    for j in range(N):
        if (i>>j)&1:
            lie[j] = 0
    for j in range(N):
        for k in range(N):
            if j==k:
                continue
            #嘘をついているので、無視
            if lie[k]==0:
                continue
            #k番目の証言で
            if A[k][j]!=lie[j]:
                flg = 1
    if flg==0:
        ans = max(ans, sum(lie))

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    hatsugen_dic = {}
    inlis = []
    anslis = []

    n= int(input())
    for s in range(n):
        a = int(input())
        for _ in range(a):
            inlis.append(list(map(int, input().split())))
        hatsugen_dic[s] = inlis
        #print(s, inlis)
        inlis = []
    #print(hatsugen_dic)

    for i in range(2**n - 1, -1, -1):   #iは正直/嘘を全列挙（人数n人に対して2^n個のケースを順番に試す）
        cnt = 0
        for j in range(n):              #jはj番目の発言者の辞書から発言リストを取り出し、それぞれiのケースと正しいかを見る
            #print(i, j)
            if ((i >> j) & 1):          #iを二進数でj桁ずらした時に、1（正直者）かどうかチェック。1ならばチェック、0ならシカト
                hatsugen_j = hatsugen_dic[j]
                #print(i, j, lis_j,  lis_j[0][0], lis_j[0][1])
                for k in range(len(hatsugen_j)):        #kはjの発言の個数。何人分言及しているか
                    if (i + hatsugen_j[k][1]) % 2 == 0:
                        #print(i, j, k, lis_j, lis_j[k][0], lis_j[k][1])
                        pass
                    else:
                        #print("i>>lis_j[k][0]-1:", (i + hatsugen_j[k][1]) % 2)
                        #print(i, j, k, lis_j, lis_j[k], lis_j[k][0], lis_j[k][1] , cnt)
                        cnt += 1
        if cnt == 0:
            count = 0
            while i:
                count += i & 1
                i >>= 1
            #print(count)
            anslis.append(count)
    print(max(anslis))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    indic = {}
    inlis = []
    anslis = []

    n= int(input())
    for s in range(n):
        a = int(input())
        for _ in range(a):
            inlis.append(list(map(int, input().split())))
        indic[s] = inlis
        #print(s, inlis)
        inlis = []
    #print(indic)
    for i in range(2**n - 1, -1, -1):
        cnt = 0
        for j in range(n):
            #print(i, j)
            if ((i >> j) & 1):
                lis_j = indic[j]
                #print(i, j, lis_j,  lis_j[0][0], lis_j[0][1])
                for k in range(len(lis_j)):
                    if (i + lis_j[k][1]) % 2 == 0:
                        #print(i, j, k, lis_j, lis_j[k][0], lis_j[k][1])
                        pass
                    else:
                        #print("i>>lis_j[k][0]-1:", (i >> lis_j[k][0]-1)^lis_j[k][1]%2)
                        #print(i, j, k, lis_j, lis_j[k][0], lis_j[k][1], cnt)
                        cnt += 1
        if cnt == 0:
            count = 0
            while i:
                count += i & 1
                i >>= 1
            #print(count)
            anslis.append(count)
    print(max(anslis))




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())

A=[]
test = []
for i in range(N):
    A_i= int(input())
    A.append(A_i)
    for j in range(A_i):
        x,y= map(int,input().split())

        test.append([x-1,y])

print(A)
print(test)

total = 0
for i in range(2**N):
    
    Honests=[0]*N
    
    for j in range(N):

        if (i>>j) &1:

            A_j = A[j]
            
            for k in range(A_j):
                x,y =test[j][0],test[j][1]

                x-=1
                if y ==1:
                    Honests[x]=1
                else:
                    Honests[x]=0
        else:
            A_j=A[j]

            for k in range(A_j):
                x,y =test[j][0],test[j][1]

                x-=1
                if y ==1:
                    Honests[x]=0
                else:
                    Honests[x]=1
            
    total = max(total,max(Honests))

print(total)

Submission status: Wrong Answer

Solution code:
n=int(input())

l=[ []*n for _ in range(n)]
a=[]

for i in range(n):
    A=int(input())
    a.append(A)
    for j in range(a[i]):
        x=list(map(int,input().split()))
        l[i].append(x)
ans=0
cnt=0
k=0
for i in range(1<<n):
    ans=max(cnt,ans)
    cnt=0
    k=0
    p=0
    for j in range(n):
        for t in range(a[j]):
            if (i>>j)%2==1:
                p+=1
                if (i>>(l[j][t][0]-1))%2==l[j][t][1]:
                    k+=1
        if k==a[j]-p:
            cnt+=1
print(max(ans,cnt))

Submission status: Wrong Answer

Solution code:
n=int(input())

l=[ []*n for _ in range(n)]
a=[]

for i in range(n):
    A=int(input())
    a.append(A)
    for j in range(a[i]):
        x=list(map(int,input().split()))
        l[i].append(x)
ans=0
cnt=0
k=0
for i in range(1<<n):
    print(cnt)
    ans=max(cnt,ans)
    cnt=0
    k=0
    p=0
    for j in range(n):
        for t in range(a[j]):
            if (i>>j)%2==1:
                p+=1
                if (i>>(l[j][t][0]-1))%2==l[j][t][1]:
                    k+=1
        if k==a[j]-p:
            cnt+=1
print(max(ans,cnt))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
try:z = [eval("[i] + list(map(int, input().split())),"*int(input())) for i in range(n)]
except SyntaxError:print(n);exit()
except EOFError:print(0);exit()
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in chain.from_iterable(z)):
        c = max(c, sum(j))
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
try:z = [eval("[i] + list(map(int, input().split())),"*int(input())) for i in range(n)]
except SyntaxError:print(n);exit()
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in chain.from_iterable(z)):
        c = max(c, sum(j))
print(c)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
try:z = [eval("[i] + list(map(int, input().split())),"*int(input())) for i in range(n)]
except SyntaxError:print(0);exit()
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in chain.from_iterable(z)):
        c = max(c, sum(j))
print(c)

Submission status: Wrong Answer

Solution code:
def main():
    # 入力
    n = int(input())

    boolls = [[]]
    for i in range(n):
        tmpls = []
        for x in boolls:
            y = x.copy()
            x.append(True)
            y.append(False)
            tmpls.append(x)
            tmpls.append(y)
        boolls = tmpls

    boolls.sort(key=lambda _: _.count(True), reverse=True)

    xyls = []
    for i in range(n):
        ai = int(input())
        tuples = []
        for j in range(ai):
            x, y = map(int, input().split())
            tuples.append((x, y == 1))
        xyls.append(tuples)

    tmpTrueCnt = n
    max_cnt = 0
    for boolx in boolls:
        truecnt = boolx.count(True)
        if truecnt == 0:
            break
        if max_cnt > truecnt:
            break

        if tmpTrueCnt > truecnt:
            tmpTrueCnt = truecnt

        ok = True
        for i in range(len(boolx)):
            tf = boolx[i]
            if tf:
                zz = xyls[i]
            else:
                zz = [(x[0], not x[1]) for x in xyls[i]]

            for message in zz:
                if boolx[message[0] - 1] != message[1]:
                    ok = False
                    break
            if not ok:
                break

        if ok:
            max_cnt = tmpTrueCnt
            break

    print(max_cnt)


main()

Submission status: Wrong Answer

Solution code:
N=int(input())

Honests =['']*N

for i in range(N):
    
    A_i = int(input())
    
    for j  in range(A_i):

        x_ij,y_ij = map(int,input().split())
        x_ij=x_ij-1

        if y_ij==0:
            Honests[x_ij] += '0'
        else:
            Honests[x_ij] += '1'

print(Honests) 

cnt=0
cnt_0=0
cnt_un=0

for i in Honests:
    cnt += i.count('1')
    cnt_0 += i.count('0')
    if '' == i:
        cnt_un+=1

if cnt==0 and cnt_0>0:
    print(0)
    exit(0)

print(cnt-(cnt_0-cnt_un))