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:
N = int(input())
ans = 0

evidence = [[] for n in range(N)]

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

ans = 0
for n in range(2 ** N):
    boolean = True
    tmp = 0
    #print(bin(n))
    for i, lis_item in enumerate(evidence):
        if not boolean:
            break
        if (1 << i) & n:
            #print(i)
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                #print(x, y)
                if ((1 << (x-1)) & n) == (y << (x-1)):  
                    boolean = True
                else:
                    boolean = False
                    break
        else:
            for j in range(len(lis_item)):
                x, y = lis_item[j][0], lis_item[j][1]
                y = (y+1) % 2
                if (1 << (x-1) & n) == (y << (x-1)):
                    #print(x, y)
                    boolean = True
                else:
                    boolean = False
                    break
    if boolean:
        ones = 0
        for t in range(15, -1, -1):
            if n - 2 ** t >= 0:
                n -= 2 ** t
                ones += 1
            if n == 0:
                break
        ans = max(ans, ones)
        #print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:

#人数
N = int(input())

ans = 0

#証言テーブル
syo = [ [] for i in range(N)]

for i in range(N):
    Ai = int(input())
    for j in range(Ai):
        xi,yi = map(int,input().split())
        #xiは添字とずれるので -1 する
        xi -= 1
        syo[i].append([xi,yi])

#bit全探索
for i in range(2**N):
    honest = 0
    mujun = False
    for j in range(N):
        #j番目の人が正直者(1)かどうか
        if ( (i >> j) & 1):
            #証言の検証を行う
            for k in range(len(syo[j])):
                #証言があっているか
                if ((i >> syo[j][k][0]) & 1) == syo[j][k][1] :
                    if k == (len(syo[j]) -1):
                        honest += 1
                    continue
                else:
                    mujun = True
                    break
        if mujun == True:
            honest = 0
            break
    ans = max(ans,honest)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
xy = []

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

# print(a)
# print(xy)

ans = 0

for i in range(2 ** n):
    memo = [1] * n
    for j in range(n):
        if (i >> j) & 1:
            memo[n - j - 1] = 0
    # print(memo)

    for p in range(n):
        flag = True
        for q in range(a[p]):
            x = xy[p][q][0]
            y = xy[p][q][1]
            if memo[p] == 1 and memo[x - 1] != y:
                flag = False
                break
            elif memo[p] == 0 and memo[x - 1] == y:
                flag = False
                break
        if not flag:
            break

    if flag:
        ans = max(ans, memo.count(1))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
answers = []
for i in range(N):
    A = int(input())
    answer = []
    for i in range(A):
        x, y = input().split(" ")
        answer.append([int(x), int(y)])
    answers.append(answer)
# print(answers)

honests = []
for i in range(N):
    honest = [0] * N
    for j, k in answers[i]:
        if k == 0:
            honest[j-1] = -1
        else:
            honest[j-1] = k
    honests.append(honest)
# print(honests)

honest_table = []
for i in range(N):
    honest_table.append([row[i] for row in honests])

#print(honest_table)
max = max([sum(i) for i in honest_table])

if max == 0:
    print("0")
elif max == -1:
    print(1)
else:
    print(max+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
answers = []
for i in range(N):
    A = int(input())
    answer = []
    for i in range(A):
        x, y = input().split(" ")
        answer.append([int(x), int(y)])
    answers.append(answer)
# print(answers)

honests = []
for i in range(N):
    honest = [0] * N
    for j, k in answers[i]:
        if k == 0:
            honest[j-1] = -1
        else:
            honest[j-1] = k
    honests.append(honest)
# print(honests)

honest_table = []
for i in range(N):
    honest_table.append([row[i] for row in honests])

#print(honest_table)
max = max([sum(i) for i in honest_table])

if max == 0:
    print("0")
else:
    print(max+1)

Submission status: Wrong Answer

Solution code:
import itertools
N=int(input())
A=[[] for i in range(N)]
for i in range(N):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        A[i].append((x-1,y))
#print(A)
ans=0
for seq in itertools.product(range(2),repeat=N):
    flag=1
    for i in range(N):
        for pair in A[i]:
            x,y=pair
            if seq[i]==1:
                if seq[x]!=y:
                    flag=0
                    break
            else:
                if seq[x]==y:
                    flag=0
                    break
        if flag==0:
            break
    if flag==1:
        ans=max(ans,sum(seq))
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
l = list(map(int,input().split()))
ans = 0

comb = list(itertools.combinations(l,2))

for i in range(len(comb)):
    k = int(bin(comb[i][0] ^ comb[i][1]),0)
    ans += k
    ans %= 10**9+7

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
testimony_list=[[[-1,-1] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	for k in range(n):
		if kind_l[k]==1:
			for m in range(a):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if subject or judge==-1:continue
				if kind_l[subject]!=judge:
					kind_l=[0 for _ in range(n)]
					break
	ans=max(ans,sum(kind_l))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
testimony_list=[[[-1,-1] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	for k in range(n):
		if kind_l[k]==1:
			for m in range(a):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if subject or judge==-1:continue
				if kind_l[subject]!=judge:
					kind_l=[0 for _ in range(n)]
					break
	ans=max(ans,sum(kind_l))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
testimony_list=[[[0,0] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	for k in range(n):
		if kind_l[k]==1:
			for m in range(a):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if kind_l[subject]!=judge:
					kind_l=[0 for _ in range(n)]
					break
	ans=max(ans,sum(kind_l))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
testimony_list=[[[0,0] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y
print(testimony_list)

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	print(kind_l)
	for k in range(n):
		if kind_l[k]==1:
			for m in range(a):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if kind_l[subject]!=judge:
					kind_l=[0 for _ in range(n)]
					break
	ans=max(ans,sum(kind_l))
print(ans)

Submission status: Wrong Answer

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

tf = [0]*n
ans = 0
for i in range(n**2):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
    else:
      tf[j] = 0
  b = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
  if b == 1 and sum(tf) > ans:
    ans = sum(tf)

print(ans)

Submission status: Wrong Answer

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

tf = [0]*n
ans = 0
for i in range(n**2):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
    else:
      tf[j] = 0
  print(tf)
  b = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
  print(i, b)
  if b == 1 and sum(tf) > ans:
    ans = sum(tf)

print(ans)

Submission status: Wrong Answer

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

tf = [0]*n
ans = 0
for i in range(n**2):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
  b = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
  if b == 1 and sum(tf) > ans:
    ans = sum(tf)

print(ans)

Submission status: Wrong Answer

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

tf = [0]*n
ans = 0
b = 1
for i in range(n**2):
  for j in range(n):
    if (i >> j) & 1:
      tf[j] = 1
  for k in range(n):
    if tf[k] == 1:
      for l in range(a[k]):
        if tf[xy[k][l][0]-1] != xy[k][l][1]:
          b = 0
          break
    if b == 1 and sum(tf) > ans:
      ans = sum(tf)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0 for i in range(n)]
X=[]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x = list(map(int,input().split()))
    X.append(x)
speak = 0
max_honest=0
for i in range(n):
  honest=1
  flag = 0
  for j in range(speak,speak + a[i]):
    k=0
    for k in range(len(a)):
      if X[k][0] == i+1:
        break
    if k != len(a):
      if X[k][1] == 0 and X[j][1] == 1:
        flag = 0
        break
      elif X[k][1] == 1 and X[j][1] == 0:
        flag = 0
        break
      else:
        flag = 1
        if X[j][1]==1:
          honest += 1
  speak += a[i]
  if flag:
    max_honest=max(max_honest,honest)
print(max_honest)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0 for i in range(n)]
X=[]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x = list(map(int,input().split()))
    X.append(x)
speak = 0
max_honest=0
for i in range(n):
  honest=1
  flag = 0
  for j in range(speak,speak + a[i]):
    k=0
    for k in range(len(a)):
      if X[k][0] == i+1:
        break
    if X[k][1] == 0 and X[j][1] == 1:
      flag = 0
      break
    elif X[k][1] == 1 and X[j][1] == 0:
      flag = 0
      break
    else:
      flag = 1
      if X[j][1]==1:
        honest += 1
  speak += a[i]
  if flag:
    max_honest=max(max_honest,honest)
print(max_honest)

Submission status: Wrong Answer

Solution code:
import itertools
import copy

n = int(input())
indexes = [_ for _ in range(1, n+1)]

def ifCorrect(data, fakes):
    answer_sheet = [-1 for i in range(n+1)]
    for i in fakes:
        answer_sheet[i] = 0

    for i in range(len(data)):
        for j in data[i]:
            if not i in fakes:
                if answer_sheet[j[0]] == -1:
                    if j[1] == 0 and not j[0] in fakes:
                        return False
                    else:
                        answer_sheet[j[0]] = j[1]
                elif not answer_sheet[j[0]] == j[1]:
                    print(answer_sheet)
                    print("zan")
                    return False
                    
    return True

data = [[] for _ in range(n+1)]
for i in range(n):
    id = int(input())
    for _ in range(id):
        x, y = map(int, input().split(" "))
        data[i+1].append([x,y])

fakePersonCount = 0
flag = True
while fakePersonCount <= n and flag:
    comb = itertools.combinations(indexes, fakePersonCount)
    for fakePeople in comb:
        if ifCorrect(data, fakePeople):
            print(n - fakePersonCount)
            flag = False
            break
    fakePersonCount += 1

if flag:
    print(0)

#[[], [[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
    
################ DANGER ################
test = ""
#test = \
"""
3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0
ans 0
"""
"""
3
1
2 1
1
1 1
1
2 0
ans 2
"""
"""
2
1
2 0
1
1 0
ans 1
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################

n = int(input2())
a = [None] * (n+1)
for i in range(1, n+1):
    ai = int(input2())
    a[i] = [tuple(map(int, input2().split())) for i in range(ai)]
    

def bitsearch(bit, *, start=0):
    end = 2 ** bit
    len0 = len(format(end, "b"))
    return [format(i, "b").zfill(len0) for i in range(start, end)] 


cand = [0]
for b in bitsearch(n):
    lie, i = 0, 1
    while (not lie) and i < n+1:
        for c in a[i]:
            if not (int(b[i]) ^ c[1] ^ int(b[c[0]])):
                lie += 1            
        i += 1
        
    if not lie:
        cand.append(b.count("1"))
        
print(max(cand))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
    
################ DANGER ################
test = ""
#test = \
"""
3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0
ans 0
"""

"""
3
1
2 1
1
1 1
1
2 0
ans 2
"""

"""
2
1
2 0
1
1 0
ans 1
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################

n = int(input2())
a = [None] * (n+1)
for i in range(1, n+1):
    ai = int(input2())
    a[i] = [tuple(map(int, input2().split())) for i in range(ai)]
    

def bitsearch(bit, *, start=0):
    end = 2 ** bit
    len0 = len(format(end, "b"))
    return [format(i, "b").zfill(len0) for i in range(start, end)] 


cand = [0]
for b in bitsearch(n):
    lie = 0
    i = 1
    while not lie and i < n+1:
        lie = 0
        for c in a[i]:
            # print(int(b[i]), c[1], int(b[c[0]]))
            if not int(b[i]) ^ c[1] ^ int(b[c[0]]):
                lie += 1            
        i += 1
        
    if not lie:
        cand.append(b.count("1"))
        
print(max(cand))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
mtx = []

for i in range(n):
    a = int(input())
    l = []
    for j in range(a):
        x,y = map(int, input().split())
        l.append([x, y])
    mtx.append(l)

def counter(sample):
    if sample == 0:
        return 0
    else:
        return (sample >> 1) + (sample & 1) #末尾が１なら１をたす

count = 0
for sample in range(2**n):
    judge = True
    for i in range(n):
        if not sample & (1 << i):
            continue
        else:
            for j in mtx[i]:
                if ((sample >> (j[0] - 1)) & 1) ^ j[1]:
                    judge = False
                    break
            if not judge:
                break
    if judge:
        count = max(count, counter(sample))
    

print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
llie=[[] for i in range(N)]
for i in range(N):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        if y==0:
            llie[i].append(x)
print(llie)
ans=0
for i in range(2**N):
    print("i",i)
    dlie={}
    dtrue={}
    tmpsum=0
    f=0
    for j in range(N):
        if i&1:
            if j+1 in dlie:
                f=1
                break
            else:
                for x in llie[j]:
                    if x in dtrue:
                        f=1
                        break
                    #dlie[j+1]=1
                    dlie[x]=1
                if f==0:
                    tmpsum+=1
                    dtrue[j+1]=1
                    #i>>=1
                    #continue
                else:
                    f==1
                    break
            #tmpsum+=1
        else:
            if j+1 in dtrue:
                f==1
                break
        i>>=1

    #else:
    if f==1:
        ans=max(ans,tmpsum)
        #ans=max(ans,N-len(dlie))
        #print("j",j)
    print("ans",ans)
#print(dtrue)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**n):
    s = format(i, "b").zfill(n)
    flag = 1
    for j in range(len(s)):
        if s[j] == "1":
            for k in range(len(v[j])):
                if v[j][k][1] == 1 and s[v[j][k][0]-1] == "0":
                    flag = 0
                    break
                if v[j][k][1] == 0 and s[v[j][k][0]-1] == "1":
                    flag = 0
                    break
        else:
            for k in range(len(v[j])):
                if v[j][k][1] == 1 and s[v[j][k][0]-1] == "1":
                    flag = 0
                    break
                if v[j][k][1] == 0 and s[v[j][k][0]-1] == "0":
                    flag = 0
                    break
    if flag == 1:
        ans = max(ans, s.count("1"))

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

ans = 0

for _ in range(n):
  a = int(input())
  for _ in range(a):
    x,y = map(int,input().split())
    if y == 1:
      ans = ans + 1

if ans == 0:
  print(1)
else:
  print(ans%n)

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
import math
from copy import copy
import sys
from queue import Queue, LifoQueue, PriorityQueue
from collections import defaultdict
from operator import itemgetter

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    N = int(readline())

    d = defaultdict(list)
    for i in range(N):
        A = int(readline())
        for _ in range(A):
            x, y = map(int, readline().split())                
            d[i].append((x-1, y))
            
    ret = 0
    for i in range(2 ** N):
        contradiction = False
        for j in range(N):
            for x, y in d[j]:
                if (i >> j) & 1:
                    if (i >> x) & 1:
                        if y == 0:
                            contradiction = True
                            break
                    else:
                        if y == 1:
                            contradiction = True
                            break
                else:
                    if (i >> x) & 1:
                        if y == 1:
                            contradiction = True
                            break
                    else:
                        if y == 0:
                            contradiction = True
                            break

        if contradiction:
            continue
        else:
            ret = max(bin(i).count("1"), ret)

    print(ret)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import copy

n = int(input())
indexes = [_ for _ in range(1, n+1)]

def ifCorrect(data, sub):
    answer_sheet = [-1 for i in range(n+1)]
    corrects = []
    for i in range(1,n+1):
        if i not in sub:
            answer_sheet[i] = 1

    for i in data:
        for j in i:
            if answer_sheet[j[0]] == -1:
                answer_sheet[j[0]] = j[1]
            elif answer_sheet[j[0]] == 0:
                if j[1] != 0:
                    return False
            elif answer_sheet[j[0]] == 1:
                if j[1] != 1:
                    return False
                    
    return True

data = [[] for _ in range(n+1)]
for i in range(n):
    id = int(input())
    for _ in range(id):
        x, y = map(int, input().split(" "))
        data[i+1].append([x,y])

fakePersonCount = 0
flag = True
while fakePersonCount <= n and flag:
    comb = itertools.combinations(indexes, fakePersonCount)
    for fakePeople in comb:
        turndata = copy.deepcopy(data)
        for i in fakePeople:
            if turndata[i] != []:
                for j in turndata[i]:
                    if j[1] == 0:
                        j[1] = 1
                    else:
                        j[1] = 0
        if ifCorrect(turndata, fakePeople):
            print(n-fakePersonCount)
            flag = False
            break
    fakePersonCount += 1

if flag:
    print(0)

#[[], [[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

Submission status: Wrong Answer

Solution code:
import itertools
import copy

n = int(input())
indexes = [_ for _ in range(1, n+1)]

def ifCorrect(data, sub):
    answer_sheet = [-1 for i in range(n+1)]
    for i in data:
        for j in i:
            if answer_sheet[j[0]] == -1:
                answer_sheet[j[0]] = j[1]
            elif answer_sheet[j[0]] == 0:
                if j[1] != 0:
                    return False
            elif answer_sheet[j[0]] == 1:
                if j[1] != 1:
                    return False
    for i in range(1,n+1):
        if i not in sub:
            if answer_sheet[i] != 1:
                return False
    return True

data = [[] for _ in range(n+1)]
for i in range(n):
    id = int(input())
    for _ in range(id):
        x, y = map(int, input().split(" "))
        data[i+1].append([x,y])

fakePersonCount = 0
flag = True
while fakePersonCount <= n and flag:
    comb = itertools.combinations(indexes, fakePersonCount)
    for fakePeople in comb:
        turndata = copy.deepcopy(data)
        for i in fakePeople:
            if turndata[i] != []:
                for j in turndata[i]:
                    if j[1] == 0:
                        j[1] = 1
                    else:
                        j[1] = 0
        if ifCorrect(turndata, fakePeople):
            print(n-fakePersonCount)
            flag = False
            break
    fakePersonCount += 1

if flag:
    print(0)

#[[], [[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

Submission status: Wrong Answer

Solution code:
import itertools
import copy

def ifCorrect(data):
    answer_sheet = [-1 for i in range(n+1)]
    for i in data:
        for j in i:
            if answer_sheet[j[0]] == -1:
                answer_sheet[j[0]] = j[1]
            elif answer_sheet[j[0]] == 0:
                if j[1] != 0:
                    return False
            elif answer_sheet[j[0]] == 1:
                if j[1] != 1:
                    return False
    return True

n = int(input())

indexes = [_ for _ in range(1, n+1)]

data = [[] for _ in range(n+1)]
for i in range(n):
    id = int(input())
    for _ in range(id):
        x, y = map(int, input().split(" "))
        data[i+1].append([x,y])

fakePersonCount = 0
flag = True
while fakePersonCount <= n and flag:
    comb = itertools.combinations(indexes, fakePersonCount)
    for fakePeople in comb:
        turndata = copy.deepcopy(data)
        for i in fakePeople:
            if turndata[i] != []:
                for j in turndata[i]:
                    if j[1] == 0:
                        j[1] = 1
                    else:
                        j[1] = 0
        if ifCorrect(turndata):
            print(n-fakePersonCount)
            flag = False
            break
    fakePersonCount += 1

if flag:
    print(0)

#[[], [[2, 1], [3, 0]], [[3, 1], [1, 0]], [[1, 1], [2, 0]]]

Submission status: Wrong Answer

Solution code:
N = int(input())
g = [[-1]*N for i in range(N)] #何も証言していないのを-1。i番目の人がj番目の人を正直ものといっているか、不親切といっているか、なにもいってないか。

for i in range(N):
    A = int(input())
    for i in range(A):
        a,x = map(int, input().split())
        a -= 1
        g[i][a] = x
ans = 0
for i in range(1 << N):
    d=[0]*N
    for j in range(N):
        if (i>>j & 1):
            d[j] = 1
    ok = True
    for j in range(N):
        if d[j]: #正直者だと割り当てをした人を見る
            for k in range(N):
                if g[j][k] == -1: continue
                if g[j][k] != d[k]: ok = False #jの人の証言が、実際の割り当てとあっているかどうかを判断
    if ok:
        ans = max(ans, bin(i).count("1"))
print(ans)

Submission status: Wrong Answer

Solution code:
def checker(bbit,listN,N):
    i = 0
    j = 0
    ng = False
    #print(N)
    #print(listN)
    #print(bin(bbit))
    while N > i :
        j=0
        checkFig = 3
        ibit = 1 << i
        while N > j :
            cbit = 1 << j
            if bbit & cbit == 0 :
                #print("A:{} {}".format(j,i))
                pass
            elif listN[j][i] == 3 :
                #print("B:{} {}".format(j,i))
                pass
            elif (listN[j][i] == 0) and (bbit & ibit != 0):
                ng = True
                break
            elif checkFig == 3 :
                #print("C:{} {}".format(j,i))
                checkFig = listN[j][i]
            elif checkFig != listN[j][i] :
                ng = True
                #print("D:{} {}".format(j,i))
                break
            j += 1
        if ng :
            #print(ng)
            break
        else :
            i +=1
    return (not ng)


def main():
    N = int(input())
    listA = [[3 for j in range(N)] for k in range(N)]
    n = 0
    while N > n :
        a = int(input())
        i = 0
        while a > i:
           x,y  = map(int,input().split())
           listA[n][x-1] = y
           i += 1
        n += 1
        
    honestBit = pow(2, N)-1
    honest = 0
    
    while honestBit > 0:
        ok = checker(honestBit,listA,N)
        if ok :
            okbit = honestBit
            oknum = 0
            while okbit > 0 :
                oknum += (okbit % 2) 
                okbit = okbit >> 1
            if oknum > honest :
                honest = oknum 
        honestBit -= 1
    print(honest)
    

main()

Submission status: Wrong Answer

Solution code:

def checker(bbit,listN,N):
    i = 0
    j = 0
    ng = False
    #print(N)
    #print(listN)
    #print(bin(bbit))
    while N > i :
        j=0
        checkFig = 3
        ibit = 1 << i
        while N > j :
            cbit = 1 << j
            if bbit & cbit == 0 :
                #print("A:{} {}".format(j,i))
                pass
            elif listN[j][i] == 3 :
                #print("B:{} {}".format(j,i))
                pass
            elif (listN[j][i] == 0) and (bbit & ibit != 0):
                ng = True
                break
            elif checkFig == 3 :
                #print("C:{} {}".format(j,i))
                checkFig = listN[j][i]
            elif checkFig != listN[j][i] :
                ng = True
                #print("D:{} {}".format(j,i))
                break
            j += 1
        if ng :
            #print(ng)
            break
        else :
            i +=1
    if N == i:
        ng =True
    return (not ng)


def main():
    N = int(input())
    listA = [[3 for j in range(N)] for k in range(N)]
    n = 0
    while N > n :
        a = int(input())
        i = 0
        while a > i:
           x,y  = map(int,input().split())
           listA[n][x-1] = y
           i += 1
        n += 1
        
    honestBit = pow(2, N)-1
    honest = 0
    
    while honestBit > 0:
        ok = checker(honestBit,listA,N)
        if ok :
            okbit = honestBit
            oknum = 0
            while okbit > 0 :
                oknum += (okbit % 2) 
                okbit = okbit >> 2        
            if oknum > honest :
                honest = oknum 
        honestBit -= 1
    print(honest)
    

main()

Submission status: Wrong Answer

Solution code:
def checker(bbit,listN,N):
    i = 0
    j = 0
    ng = False
    #print(N)
    #print(listN)
    while N > i :
        j=0
        checkFig = 3
        ibit = 1 << i
        while N > j :
            cbit = 1 << j
            if bbit & cbit == 0 :
                #print("A:{} {}".format(j,i))
                pass
            elif listN[j][i] == 3 :
                #print("B:{} {}".format(j,i))
                pass
            elif (listN[j][i] == 0) and (bbit & ibit != 0):
                ng = True
                break
            elif checkFig == 3 :
                #print("C:{} {}".format(j,i))
                checkFig = listN[j][i]
            elif checkFig != listN[j][i] :
                ng = True
                #print("D:{} {}".format(j,i))
                break
            j += 1
        if ng :
            #print(ng)
            break
        else :
            i +=1
    return (not ng)


def main():
    N = int(input())
    listA = [[3 for j in range(N)] for k in range(N)]
    n = 0
    while N > n :
        a = int(input())
        i = 0
        while a > i:
           x,y  = map(int,input().split())
           listA[n][x-1] = y
           i += 1
        n += 1
        
    honestBit = pow(2, N)-1
    honest = N
    while honest > 0:
        ok = checker(honestBit,listA,N)
        if ok :
            break
        honestBit -= 1
        honest -= 1

    print(honest)

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [["na"]*n for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        xi,yi = list(map(int,input().split()))
        xy[i][xi-1] = yi
#print(xy)
ans = [1 for i in range(n)]
for i in range(n):
    for j in range(n):
        if xy[i][j] == 0:
            ans[j] = 0
        else:
            pass
if (n == 2 and sum(ans) == 0):
    print(1)
else:    
    print(sum(ans))