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())
syougen = [[] for _ in range(N)]
for _ in range(N):
    kosuu = int(input())
    for i in range(kosuu):
        syougen[_].append([int(x) for x in input().split(" ")])
num = 0
for i in range(2 ** N):
    bit = i
    honest = [0 for _ in range(N)]
    k = 0
    while bit > 0:
        if bit % 2 == 1:
            for s in syougen[k]:
                honest[s[0] - 1] = s[1]
        bit >>= 1
        k += 1
    check = 0
    for j in range(N):
        check += honest[j] * 2 ** j
    if check == i:
        bit = i
        while bit > 0:
            num += bit % 2
            bit >>= 1
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())

g = [[-1]*N for i in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = [int(n) for n in input().split(' ')]
        g[i][x-1] = y

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
    if ok:
        ans = max(ans, bin(i).count("1"))

print(ans)

Submission status: Wrong Answer

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

max_honest = 0
for i in range(2 ** n):
    bin_i = format(i, '015b')[::-1]
    ok = True

    for j in range(n):
        for x, y in xys[j]:
            if (int(bin_i[j]) ^ y) == int(bin_i[x - 1]):
                ok = False
                break
        else:
            continue
        break

    if ok:
        honest = sum(int(x) for x in bin_i)
        max_honest = max(max_honest, honest)

print(max_honest)

Submission status: Wrong Answer

Solution code:
S = input()

result = 0
for i in range(len(S) // 2):
  if S[i] != S[-(i + 1)]:
    result += 1
print(result)

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(honest_list):
    global N
    global X
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1 and X[i][j] != 0:
                if X[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif X[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0 and X[i][j] != 0:
                if X[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif X[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    global X
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for j in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(honest_list):
                print(r)
                return
    print(0)
            
N = int(input())
X = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            X[i][x_ij-1] = 1
        elif y_ij == 0:
            X[i][x_ij-1] = -1
print_max_honest()

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(x, honest_list):
    global N
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1 and i != j:
                if x[i][j] == honest_list[j]:
                    return True
                elif x[i][j] == honest_list[j]:
                    return True
            elif honest_list[i] == 0 and i != j:
                if x[i][j] != honest_list[j]:
                    return True
                elif x[i][j] != honest_list[j]:
                    return True
    return False

def print_max_honest():
    global N
    global X
    
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for j in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(X, honest_list):
                print(r)
                return
    print(0)
            
N = int(input())
X = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            X[i][x_ij-1] = 1
        elif y_ij == 0:
            X[i][x_ij-1] = 0
print_max_honest()

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(x, honest_list):
    global N
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1:
                if x[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0:
                if x[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    global X
    
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for j in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(X, honest_list):
                print(r)
                return
    print(0)
            
N = int(input())
X = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            X[i][x_ij-1] = 1
        elif y_ij == 0:
            X[i][x_ij-1] = -1
print_max_honest()

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(x, honest_list):
    global N
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1:
                if x[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0:
                if x[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    global x
    
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for j in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(X, honest_list):
                print(r)
                return
    print(0)
            
N = int(input())
X = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            X[i][x_ij-1] = 1
        elif y_ij == 0:
            X[i][x_ij-1] = -1
print_max_honest()

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(x, honest_list):
    global N
    for i in range(N):
        for j in range(N):
            if honest_list[i] == 1:
                if x[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0:
                if x[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for i in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(x, honest_list):
                print(sum(honest_list))
                return
    print(0)
            
N = int(input())
x = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            x[i][x_ij-1] = 1
        elif y_ij == 0:
            x[i][x_ij-1] = -1
print_max_honest()

Submission status: Wrong Answer

Solution code:
import itertools

def check_honesty(x, honest_list):
    for i in range(len(x)):
        for j in range(len(x[i])):
            if honest_list[i] == 1:
                if x[i][j] == -1 and honest_list[j] == 1:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 0:
                    return False
            elif honest_list[i] == 0:
                if x[i][j] == -1 and honest_list[j] == 0:
                    return False
                elif x[i][j] == 1 and honest_list[j] == 1:
                    return False
    return True

def print_max_honest():
    global N
    for i in range(N):
        r = N - i
        for ite in itertools.combinations(list(range(N)), r):
            honest_list = [0 for i in range(N)]
            for n in ite:
                honest_list[n] = 1
            if check_honesty(x, honest_list):
                print(sum(honest_list))
                return
    print(0)
            
N = int(input())
x = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            x[i][x_ij-1] = 1
        elif y_ij == 0:
            x[i][x_ij-1] = -1
print_max_honest()

Submission status: Wrong Answer

Solution code:
def check_honesty(x):
    global HONEST_LIST
    for i in range(len(x)):
        for j in range(len(x[i])):
            if HONEST_LIST[i] == 1:
                if x[i][j] == -1 and HONEST_LIST[j] == 1:
                    HONEST_LIST[i] = 0
                    check_honesty(x)
                elif x[i][j] == 1 and HONEST_LIST[j] == -1:
                    HONEST_LIST[i] = 0
                    check_honesty(x)
            elif HONEST_LIST[i] == 0:
                if x[i][j] == -1 and HONEST_LIST[j] == -1:
                    HONEST_LIST[j] = 0
                    check_honesty(x)
                elif x[i][j] == 1 and HONEST_LIST[j] == 1:
                    HONEST_LIST[j] = 0
                    check_honesty(x)
            
            
N = int(input())
HONEST_LIST = [1 for i in range(N)]
x = [[0 for i in range(N)] for j in range(N)]

for i in range(N):
    A = int(input())
    for j in range(A):
        x_ij,y_ij = map(int, input().split())
        if y_ij == 1:
            x[i][x_ij-1] = 1
        elif y_ij == 0:
            x[i][x_ij-1] = -1

check_honesty(x)
print(sum(HONEST_LIST))

Submission status: Wrong Answer

Solution code:
N=int(input())
Ins=[[] for _ in range(N)]
ans=0

#bit演算用にx-1
for i in range(N):
  A=int(input())
  for _ in range(A):
    x,y=map(int,input().split())
    Ins[i].append((x-1,y))

for i in range(2**N):
  flag=1
  honest=[]
  unkind=[]
  for j in range(N):
    if (i>>j)&1:
      honest.append(j)
    else:
      unkind.append(j)
  for k in range(N):
    if k in honest:
      for l in Ins[k]:
        if l[1]==1 and l[0] in unkind:
          flag=0
          break
        elif l[1]==0 and l[0] in honest:
          flag=0
          break
    if flag==1:
        ans=max(ans,len(honest))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
data = []
for _ in range(N):
	A = int(input())
	items = []
	for __ in range(A):
		x, y = map(int, input().split())
		items.append((x - 1, y))
	data.append(items)
 
best = 0
 
def check(i):
    for j in range(N):
        if ((i >> j) & 1) == 1:           
            for x, y in data[j]:
                if y !=((i >> x) & 1):return False						
    return True
 
for i in range(2**N >> 1):
    count=0
    for j in range(N):count += ((i >> j) & 1)
    if count>best:
        if check(i):best = count
	
print(best)

Submission status: Wrong Answer

Solution code:
N=int(input())
all=[]
for i in range(N):
    A_N=int(input())
    grid=[]
    for j in range(A_N):
        a=list(map(int, input().split()))
        grid.append(a)
    all.append(grid)
print(all)
ans=[]
for i in range(N):# 二進数のリスト作成
    b = format(i,'b').zfill(N)
    c_l = [int(p) for p in list(b)]

    for l in range(N):# checkの開始（lは人）
        for m in range(len(all[l])):# その人の主張の数
            if c_l[all[l][m][0]-1]!=all[l][m][1]:
                break
        else:
            continue
        break
else:
    ans.append(c_l.count(1))
print(max(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

N = int(input())

claim = []

for _ in range(N):
    memo = []
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        memo.append((x,y))
    claim.append(memo)

maximam = 0
for bit in range(2**N):
    flag = True
    count = 0
    for i in range(N):
        if bit & (1<<i):
            count+=1
            for x, y in claim[i]:
                if bit & (1<<(x-1)) != y:
                    flag = False
    if flag:
        maximam = max(maximam,count)
print(maximam)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

N = int(input())

claim = []

for _ in range(N):
    memo = []
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        memo.append((x,y))
    claim.append(memo)

maximam = 0
for bit in range(2**N):
    flag = True
    count = 0
    for i in range(N):
        if bit & (1<<i):
            count+=1
            for x, y in claim[i]:
                if bit & (1>>i) != y:
                    flag = False
    if flag:
        maximam = max(maximam,count)
print(maximam)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = int(input())
    statement = [[] for i in range(N)]
    for i in range(N):
        message = int(input())
        for j in range(message):
            num, tmp = map(int, input().split())
            if tmp == 1:
                TF = True
            else:
                TF = False
            statement[i].append((num, TF))
    ans = 0
    for i in range(1 << (N-1)):
        status = [False] * 15
        tmp_ans = 0
        for j, c in enumerate(format(i, '015b')[::-1]):
            if c == '1':
                status[j] = True
                tmp_ans += 1
        if tmp_ans <= ans:
            continue
        flag = True
        for j, person in enumerate(statement):
            if not status[j]:
                continue
            for state in person:
                if status[state[0]-1] != state[1]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            ans = max(ans, tmp_ans)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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-1)):
  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)

Submission status: Wrong Answer

Solution code:
n = int(input())
say = []
for _ in range(n):
    a = int(input())
    say.append([tuple(map(int, input().split())) for _ in range(a)])

def to_list(x, n):
    li = []
    for i in range(n):
        li.append((x>>i)&1)
    return li

res = 0
for bits in range(2**n):
    is_honest = to_list(bits, n)
    flg = False
    for i in range(n):
        for x, y in say[i]:
            if is_honest[x-1] != int(y == is_honest[i]):
                flg = True
    if  not flg:
        res = max(res, sum(is_honest))
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations

n = int(input())

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

res = 0
for i in range(1,n+1):
    for c in combinations(range(n), i):
        flag = True
        for X in c:
            for x,y in al[X-1]:
                if y==1:
                    if x not in c:
                        flag = False
                else:
                    if x in c:
                        flag = False
        if flag:
            res = i
            break

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
HOU = []
for i in range(n):
    tmp = int(input())
    for _ in range(tmp):
        x, y = (map(int, input().split()))
        HOU.append([i, x - 1, bool(y)])

anssum = 0
for i in range(2 ** n):
    flag = True
    #print(bin(i))
    for j in range(len(HOU)):
        #print(i >> HOU[j][0] & 1, HOU[j][0])
        if (i >> HOU[j][0]) & 1:
            if HOU[j][2] == i >> HOU[j][1] & 1:
                continue
            else:
                flag = False
                break
        else:
            if HOU[j][2] != i >> HOU[j][1] & 1:
                continue
            else:
                flag = False
                break


    if flag:
        anssum = max(anssum,str(bin(i)).count('1'))

print(anssum)

Submission status: Wrong Answer

Solution code:
n = int(input())
HOU = []
for i in range(n):
    tmp = int(input())
    for _ in range(tmp):
        x, y = (map(int, input().split()))
        HOU.append([i, x - 1, bool(y)])

anssum = 0
for i in range(2 ** n):
    flag = True
    #print(bin(i))
    for j in range(len(HOU)):
        print(i >> HOU[j][0] & 1, HOU[j][0])
        if (i >> HOU[j][0]) & 1:
            if HOU[j][2] == i >> HOU[j][1] & 1:
                continue
            else:
                flag = False
                break
        else:
            if HOU[j][2] != i >> HOU[j][1] & 1:
                continue
            else:
                flag = False
                break


    if flag:
        anssum = max(anssum,str(bin(i)).count('1'))

print(anssum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

N=int(input())

ans_l=[1]*N

if N == 1:
    print("1")
else:
    for i in range(N):
        A=int(input())
        for j in range(A):
            a,b=map(int,input().split())
            ans_l[a-1]=ans_l[a-1]*b
    print(sum(ans_l))

Submission status: Wrong Answer

Solution code:
import copy
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
HOU = []
for i in range(n):
    tmp = int(readline())
    for _ in range(tmp):
        x, y = (map(int,readline().split()))
        HOU.append([i, x - 1, bool(y)])

#print(HOU)
anssum = 0
#print(HOU)
ans = [False] * n
for i in range(2 ** n):
    tmplist = copy.deepcopy(HOU)
    flag = True
    now = str((bin(i))[2:].zfill(n))
    #print(now)
    for j in range(n):
        ans[j] = bool(int(now[j]))
    # print(ans)
    for j in range(len(HOU)):
        if not ans[tmplist[j][0]]:
            tmplist[j][2] = not tmplist[j][2]

        if ans[tmplist[j][1]] == tmplist[j][2]:
            continue
        else:
            flag = False
            #print(tmplist[j],ans[tmplist[j][1]])
            break
    if flag:
        anssum = max(anssum, sum(ans))

print(anssum)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
HOU = []
for i in range(n):
    tmp = int(input())
    for _ in range(tmp):
        x, y = (map(int, input().split()))
        HOU.append([i, x - 1, bool(y)])

#print(HOU)
anssum = 0

ans = [False] * n
for i in range(2 ** n):
    tmplist = copy.deepcopy(HOU)
    flag = True
    now = str((bin(i))[2:].zfill(n))
    #print(now)
    for j in range(n):
        ans[j] = bool(int(now[j]))
    # print(ans)
    for j in range(len(HOU)):
        if not ans[tmplist[j][0]]:
            tmplist[j][2] = not tmplist[j][2]

        if ans[tmplist[j][1]] == tmplist[j][2]:
            continue
        else:
            flag = False
            #print(ans,HOU[j],ans)
            break
    if flag:
        anssum = max(anssum, sum(ans))

print(anssum)

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
HOU = []
for i in range(n):
    tmp = int(input())
    for _ in range(tmp):
        x, y = (map(int, input().split()))
        HOU.append([i, x - 1, bool(y)])

#print(HOU)
anssum = 0
print(HOU)
ans = [False] * n
for i in range(2 ** n):
    tmplist = copy.deepcopy(HOU)
    flag = True
    now = str((bin(i))[2:].zfill(n))
    #print(now)
    for j in range(n):
        ans[j] = bool(int(now[j]))
    # print(ans)
    for j in range(len(HOU)):
        if not ans[tmplist[j][0]]:
            tmplist[j][2] = not tmplist[j][2]

        if ans[tmplist[j][1]] == tmplist[j][2]:
            continue
        else:
            flag = False
            print(tmplist[j],ans[tmplist[j][1]])
            break
    if flag:
        anssum = max(anssum, sum(ans))

print(anssum)

Submission status: Wrong Answer

Solution code:
n = int(input())
HOU = []
for i in range(n):
    tmplist = []
    tmp = int(input())
    for _ in range(tmp):
        x, y = (map(int, input().split()))
        HOU.append([i, x - 1, bool(y)])

#print(HOU)
anssum = 0
ans = [False] * n
for i in range(2 ** n):
    flag = True
    now = str((bin(i))[2:].zfill(n))
    for j in range(n):
        ans[j] = bool(int(now[j]))
    # print(ans)
    for j in range(len(HOU)):
        if not ans[HOU[j][0]]:
            HOU[j][2] = not HOU[j][2]

        if ans[HOU[j][1]] == HOU[j][2]:
            continue
        else:
            flag = False
            break
    if flag:
        anssum = max(anssum, sum(ans))

print(anssum)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product


def solve(string):
    n, *axy = map(int, string.split())
    m = []
    i = 0
    for _ in range(n):
        a = axy[i]
        t = [0] * n
        for x, y in zip(*[iter(axy[i + 1:i + 2 * a + 1])] * 2):
            t[x - 1] = 2 * y - 1
        m.append(t)
        i += 2 * a + 1
    m = np.asarray(m).T
    ans = [0]
    for v in product([1, -1], repeat=n):
        v = np.asarray(v)
        if ((m * v).T * (v+1) >= 0).all():
            ans.append(sum((v + 1) // 2))
    return str(max(ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product


def solve(string):
    n, *axy = map(int, string.split())
    m = []
    i = 0
    for _ in range(n):
        a = axy[i]
        t = [0] * n
        for x, y in zip(*[iter(axy[i + 1:i + 2 * a + 1])] * 2):
            t[x - 1] = 2 * y - 1
        m.append(t)
        i += 2 * a + 1
    m = np.asarray(m).T
    ans = [0]
    for v in product([1, -1], repeat=n):
        v = np.asarray(v)
        if ((m * v).T * v >= 0).all():
            ans.append(sum((v + 1) // 2))
    return str(max(ans))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import product


def solve(string):
    n, *axy = map(int, string.split())
    m = []
    i = 0
    for _ in range(n):
        a = axy[i]
        t = [0] * n
        for x, y in zip(*[iter(axy[i + 1:i + 2 * a + 1])] * 2):
            t[x - 1] = 2 * y - 1
        m.append(t)
        i += 2 * a + 1
    m = np.asarray(m).T
    for v in product([1, -1], repeat=n):
        v = np.asarray(v)
        if ((m * v).T * v >= 0).all():
            break
    return str(sum((v + 1) // 2))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))