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):
N = int(input())
a = [[] for _ in range(N)]
b = []
for i in range(N):
  A_i = int(input())
  b.append(A_i)
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
book = a
max_honest = 0

i = 0
while i < N:
  honest_p = []
  unkind_p = []
  honest_p.append(i)
  contradiction = False
  while True:
    changed = False
    for j in honest_p:
      for k in range(b[j]):
        people = book[j][k][0] - 1
        testimony = book[j][k][1]
        if testimony and people in unkind_p:
          max_honest = 0
          contradiction = True
          break
        if not testimony and people in honest_p:
          max_honest = 0
          contradiction = True
          break
        if testimony and not people in honest_p:
          honest_p.append(people)
          changed = True
    print(honest_p)
    if contradiction:
      break
    if not changed:
      break
    if len(honest_p) > max_honest:
      max_honest = len(honest_p)
  i += 1

print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if list(set(honest_p) & set(unkind_p)) != []:
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
b = []
for i in range(N):
  A_i = int(input())
  b.append(A_i)
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
book = a
max_honest = 0

i = 0
while i < N:
  honest_p = []
  unkind_p = []
  honest_p.append(i)
  contradiction = False
  while True:
    changed = False
    for j in honest_p:
      for k in range(b[j]):
        people = book[j][k][0] - 1
        testimony = book[j][k][1]
        if testimony and people in unkind_p:
          max_honest = 0
          contradiction = True
          break
        if not testimony and people in honest_p:
          max_honest = 0
          contradiction = True
          break
        if testimony and not people in honest_p:
          honest_p.append(people)
          changed = True
        if testimony and not people in unkind_p:
          unkind_p.append(people)
          changed = True
    if contradiction:
      break
    if len(honest_p) > max_honest:
      max_honest = len(honest_p)
    if not changed:
      break
  i += 1

print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  bin_num = bin(i)
  length = len(bin_num)-2
  for j in range(0, length):
    if (i >> j) & 1:
      doubt_honest_p.append(j+1)
    else:
      doubt_unkind_p.append(j+1)
    for k in a[j]:
      p = k[0]
      t = k[1]
      if t:
        honest_p.append(p)
      else:
        unkind_p.append(p)
  for l in doubt_honest_p:
    if not l in honest_p:
      contradiction = True
  for m in doubt_unkind_p:
    if not m in unkind_p:
      contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          honest_p.append(p)
        else:
          unkind_p.append(p)
    else:
      doubt_unkind_p.append(j+1)
  for l in doubt_honest_p:
    if not l in honest_p or l in unkind_p:
      contradiction = True
  for m in doubt_unkind_p:
    if not m in unkind_p or m in honest_p:
      contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if len(list(set(honest_p) & set(unkind_p))) != 0:
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if not len(list(set(honest_p) & set(unkind_p))):
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

N = int(input())
a = [[] for _ in range(N)]
b = []
for i in range(N):
  A_i = int(input())
  b.append(A_i)
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
book = a
max_honest = 0

i = 0
while i < N:
  honest_p = []
  unkind_p = []
  honest_p.append(i)
  contradiction = False
  while True:
    changed = False
    for j in honest_p:
      for k in range(b[j]):
        people = book[j][k][0] - 1
        testimony = book[j][k][1]
        if testimony and people in unkind_p:
          max_honest = 0
          contradiction = True
          break
        if not testimony and people in honest_p:
          max_honest = 0
          contradiction = True
          break
        if testimony and not people in honest_p:
          honest_p.append(people)
          changed = True
        if testimony and not people in unkind_p:
          unkind_p.append(people)
          changed = True
    print(honest_p)
    print(unkind_p)
    if contradiction:
      break
    if len(honest_p) > max_honest:
      max_honest = len(honest_p)
    if not changed:
      break
  i += 1

print(max_honest)

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

max_person = 0
for i in range(2**N):
  judge = True
  bin_num = bin(i)
  times = 0
  for j in reversed(bin_num):
    if j == "b":
      break
    if j == "1":
      for k in a[times]:
        if ((i >> k[0]-1) & 1) != k[1]:
          judge = False
    times += 1
  true_person = bin_num.count("1")
  if judge == True:
    max_person = max(max_person, true_person)
print(max_person)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted