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

Submission attempts (in order):
from itertools import zip_longest as zi
n=int(input())
hil=[ [ [],[] ] for i in range(n)]
for i in range(n):
  hint=int(input())
  if hint:
    for j in range(hint):
      a,s=map(int,input().split())   
      hil[a-1][s]+=[i]

ans=0
for i in range(2**n)[::-1]:
  ss=bin(i)[2:]
  s="0"*(n-len(ss))+ss
  sset=set([fg for fg in range(n) if s[fg]=="1"])
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
  if len(jjj&sset) or len(jjj&(kkk-sset)):
      break
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)

from itertools import zip_longest as zi
n=int(input())
hil=[ [ [],[] ] for i in range(n)]
for i in range(n):
  hint=int(input())
  if hint:
    for j in range(hint):
      a,s=map(int,input().split())   
      hil[a-1][s]+=[i]

ans=0
for i in range(2**n)[::-1]:
  ss=bin(i)[2:]
  s="0"*(n-len(ss))+ss
  sset=set([fg for fg in range(n) if s[fg]=="1"])
  hset=set(range(n))-sset
  print(sset,hset)
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
    
  if len(jjj&sset) or len(kkk&hset) :
    continue
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)


n=int(input())
l=[0 for i in range(n)]
for i in range(n):
  ka=int(input())
  r,w=[],[]
  for k in range(ka):
    x,y=map(int,input().split())
    r.append(x-1) if y else w.append(x-1)
  l[i]=(set(r),set(w))
ans=0
for j in range(2**n):
  v=format(j,"b").zfill(n)
  R,W=set(),set()
  RR={i for i in range(n) if v[i]=="1"}
  for h in RR:
    r,w=l[h]
    R|=r
    W|=w
  WW=set(range(n))-RR
  if len(RR&W) or len(WW&R) or len(R&W) :break
  else:ans=max(ans,len(RR))
print(ans)

from itertools import zip_longest as zi
n=int(input())
hil=[ [ [],[] ] for i in range(n)]
for i in range(n):
  hint=int(input())
  if hint:
    for j in range(hint):
      a,s=map(int,input().split())   
      hil[a-1][s]+=[i]

ans=0
for i in range(2**n)[::-1]:
  ss=bin(i)[2:]
  s="0"*(n-len(ss))+ss
  sset=set([fg for fg in range(n) if s[fg]=="1"])
  hset=set(range(n))-sset
  print(sset,hset)
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
    
  if len(jjj&sset) or len(kkk&hset) :
    contiue
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)


n=int(input())
l=[0 for i in range(n)]
for i in range(n):
  ka=int(input())
  r,w=[],[]
  for k in range(ka):
    x,y=map(int,input().split())
    r.append(x-1) if y else w.append(x-1)
  l[i]=(set(r),set(w))
ans=0
for j in range(2**n):
  v=format(j,"b").zfill(n)
  R,W=set(),set()
  RR={t for t in range(n) if v[t]=="1"}
  for h in RR:
    r,w=l[h]
    R|=r
    W|=w
  WW=set(range(n))-RR
  if len(RR&W) or len(WW&R) or len(R&W) :continue
  else:ans=max(ans,len(RR))
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted