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())
T = [[]for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        t = list(map(int,input().split()))
        T[i].append(t)
S = []
for i in range(2**N):
    f = 1
    for j in range(N):
        for k in range(len(T[j])):
            x = T[j][k][0]-1
            y = T[j][k][1]
            if (i>>j)&1:
                if (i>>x)^y:
                    f = 0
            elif (i>>j)^1:
                if not (i>>x)^y:
                    f = 0
    if f == 1:
        S.append(i)
n = len(S)
m = 0
for i in range(n):
    s = S[i]
    a = 0
    for j in range(N):
        if (s>>j)&1:
            a += 1
    m = max(a,m)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())

a_list = []
truth = {}
unkind = {}
for i in range(1,N+1):
    a = int(input())
    a_list.append(a)
    for _ in range(a):
        x, y = input().split()
        i = str(i)
        if y == '1':
            truth[i] = x
        else:
            unkind[i] = x


if len(truth) == 0:
    print(1)
elif len(truth) <= len(unkind):
    print(0)
else:
    print(len(truth))

Submission status: Wrong Answer

Solution code:
n = int(input())   #人の人数

b = []
c = []
d = []
ans = 0
for i in range(n):
    a = int(input()) #何段の証言になるか
    for l in range(a):
        x,y = list(map(int,input().split()))
        b.append(x)  #矛先
        c.append(y)  #審議
#print(b)
#print(c)
for o in range(n):
    ans = 0
    for m in range(len(b)):
        if b[m] == o+1:
            if c[m] == 1:
                ans += 1
            else:
                ans -= 1
    d.append(ans)
#print(d)
sorted(d)
if len(set(d)) == 1:
    if sum(set(d)) < 0:
        print(len(set(d)))
    else:
        print(0)
else:
    print(len(set(d)))

Submission status: Wrong Answer

Solution code:

n = int(input())

hp = 0

zs = []
all_z = True
for i in range(n):
  an = int(input())
  is_h = True
  all_z = True
  for j in range(an):
    x, y = map(int, input().split(' '))
    zs.append(zs)
    if y == 0:
      is_h = False
  if is_h:
    hp += 1
for z in zs:
  if z != 0:
    all_z = False
if all_z:
  hp += 1    
print(hp)

Submission status: Wrong Answer

Solution code:
#ABC147 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
T = [[] for i in range(n)]
F = [[] for i in range(n)]
ans = [[] for i in range(n)]
for i in range(n):
    a = ni()
    for j in range(a):
        x,y=nm()
        if y==1:
            T[x-1].append(i)
        elif y==0:
            F[x-1].append(i)

for i,t in enumerate(T):
    for tt in t:
        ans[tt].append(True)

for i,f in enumerate(F):
    for ff in f:
        ans[ff].append(False)

aaaa=0
for aaa in ans:
    if all(aaa):
        aaaa+=1
    else:
        aaaa=0  
print(aaaa)

Submission status: Wrong Answer

Solution code:
def A():
    nums = [int(n) for n in input().split()]
    if sum(nums) >= 22:
        print('bust')
    else:
        print('win')

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

def C():
    N = int(input())
    matrix = [[-1 for i in range(N)] for j in range(N)]
    for i in range(N):
        A = int(input())
        for j in range(A):
            temp = [int(n) for n in input().split()]
            matrix[i][temp[0]-1] = temp[1]
    #print(matrix)
    def equal(a1, a2, N):
        for i in range(N):
            if a1[i] != a2[i] and a1[i] != -1 and a2[i] != -1:
                return False
        return True

    ans = 0
    for i in range(N):
        testimonies = matrix[i]
        count = 0
        for j in range(N):
            if testimonies[j] == 1:
                if not equal(matrix[j], testimonies, N):
                    count = -1
                    break
                else:
                    for i in range(len(testimonies)):
                        if matrix[j][i] != -1:
                            testimonies[i] = matrix[j][i]
                    count += 1
            if testimonies[j] == -1:
                if equal(matrix[j], testimonies, N):
                    for i in range(len(testimonies)):
                        if matrix[j][i] != -1:
                            testimonies[i] = matrix[j][i]
                    count += 1
        ans = max(ans, max(0, count))
        # print(testimonies)
        # print(ans)
    print(ans)

C()

Submission status: Wrong Answer

Solution code:
n = int(input())
test = []
count = 0
a = []
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a.append(answer[1])
        if a[j] == '1':
            count += 1
        elif a[j] == '0':
            count -= 1
        else:
            continue
if count > 0:
    print(count)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
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)):
      continue
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
T = [[]for i in range(N)]
for i in range(N):
    A = int(input())
    for j in range(A):
        t = list(map(int,input().split()))
        T[i].append(t)
S = []
for i in range(2**N):
    f = 1
    for j in range(N):
        for k in range(len(T[j])):
            x = T[j][k][0]-1
            y = T[j][k][1]
            if (i>>j)&1:
                if (i>>x)^y:
                    f = 0
            elif (i>>j)^1:
                if not (i>>x)^y:
                    f = 0
    if f == 1:
        S.append(i)
n = len(S)
m = 0
for i in range(n):
    s = S[i]
    a = 0
    for j in range(N):
        if (s>>j)&1:
            a += 1
    m = max(a,m)
print(m)

Submission status: Wrong Answer

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

print(b)
    
z=0

for p in range(len(b)):
  for q in range(len(b)):
    if b[p][0]==b[q][0] and b[p][1]!=b[q][1]:
      z+=1
    print(z)

print(int(n-z/2))

Submission status: Wrong Answer

Solution code:
N = int(input())#人数
check_lst = [[None for _ in range(N)] for _ in range(N)]

for i in range(N):
    A = int(input())

    for j in range(A):
        x,y = map(int,input().split())
        check_lst[i][x-1] = y



checker = [None for _ in range(N)]#i番目の人は正直者か
for i in range(N):
    if checker[i] != None:
        continue
    for j in range(N):

        if check_lst[i][j] != 0 and check_lst[i][j] != 1:#評価がない場合
            pass

        else:#評価がある場合
            if check_lst[i][j] == 1: #iのjに対する評価が１のとき
                if check_lst[i][j] == check_lst[j][i]:
                    pass
                else:
                    checker[i] = False
                    break

            else:#iのjに対する評価が0のとき
                if checker[j] == True:#jが正直者と確定しているならば
                    checker[i] = False
                    break

                else:
                    pass

        
        if j == N-1:
            checker[i] = True
            for j in range(N):
                if j == i:
                    pass
                checker[j] = check_lst[i][j]


        
ans = 0
for e in checker:
    ans += int(True==e)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())   #人の人数

b = []
c = []
d = []
ans = 0
for i in range(n):
    a = int(input()) #何段の証言になるか
    for l in range(a):
        x,y = list(map(int,input().split()))
        b.append(x)  #矛先
        c.append(y)  #審議
#print(b)
#print(c)
for o in range(n):
    ans = 0
    for m in range(len(b)):
        if b[m] == o+1:
            if c[m] == 1:
                ans += 1
            else:
                ans -= 1
    d.append(ans)
print(d)
sorted(d)
print(sum(set(d)))
if len(set(d)) == 1:
    if sum(set(d))< 0:
        print(len(set(d)))
    else:
        print(0)
else:
    print(len(set(d)))

Submission status: Wrong Answer

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

N = int(input())
M = []
for i in range(N):
    A = int(input())
    XY = []
    for j in range(A):
        X, Y = map(int, input().split())
        XY.append([X, Y])
    M.append(XY)

# 残り嘘つき人数を渡して全パターンを列挙する
def check(n, l):
    # 残り0なら以降を全部正直者にして判定
    if n == 0:
        l += [1] * (N - len(l))
        return judge(l)
    # 残りがオーバーしてたらFalse
    if n > N - len(l):
        return False

    # iが嘘つき0
    if check(n - 1, l + [0]):
        return True
    # iが正直者1
    if check(n, l + [1]):
        return True

    return False

# 矛盾がないかチェックする
def judge(l):
    for i in range(len(M)):
        ii = M[i]
        for j in range(len(ii)):
            jj = ii[j]
            if l[jj[0] - 1] != jj[1]:
                return False
    return True

for i in range(N + 1):
    if check(i, []):
        print(i)
        break;

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
comments = {}
for i in range(n):
  a = int(input())
  comments[i] = []
  for _ in range(a):
    x, y = [int(x) for x in input().split()]
    comments[i].append([x-1, y==1])

ans = 0
for i in range(2**n):
  results = [None] * n
  for j in range(n):
    candidate = (i >> j) & 1
    if results[j] is None:
      results[j] = candidate
    if results[j] != candidate:
      break
    if candidate == False:
      continue
    if candidate == True:
      failed = False
      for comment in comments[j]:
        if results[comment[0]] is None:
          results[comment[0]] = comment[1]
        if results[comment[0]] != comment[1]:
          failed = True
          break
      if failed:
        break
  else:
    cnt = len([r for r in results if r is True])
    if cnt > ans:
      ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  8 21:12:35 2019

@author: over-
"""

N=int(input())
A=dict()
x=dict()
y=dict()
for i in range(1,N+1):
    A[i]=int(input())
    x[i]=dict()
    y[i]=dict()
    for j in range(A[i]):
        a1,a2=map(int,input().split())
        x[i][j+1]=a1
        y[i][j+1]=a2

C=2**N
ans=0
for c in range(C):
    honest=[]
    unkind=[]
    B='{:0b}'.format(c)
    B='0'*(N-len(B))+B
    bool=True
    for i in range(N):
        if B[i]==0:
            honest.append(i+1)
        else:   
            unkind.append(i+1)
        
    for k in range(1,N+1):
        if k in honest:
            for j in range(A[k]):
                if y[k][j+1]==1:
                    if x[k][j+1] in unkind:
                        bool=False
                else:
                    if x[k][j+1] in honest:
                        bool=False
    if bool: 
        count=0
        for i in range(N):
            count+=int(B[i])
        if count > ans:
            ans= count
                        
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
honest = N
matrix = [[0 for i in range(N)] for j in range(N)]
for n in range(N):
    A = int(input())
    for a in range(A):
        str_x, str_y = input().split()
        x, y = int(str_x), int(str_y)
        matrix[n][x-1] = y+1
for n in range(N):
    tmp = matrix[0][n]
    for x in range(1, N):
        if matrix[x][n] == 0: continue
        if matrix[x][n] != tmp:
            if tmp > 0:
                honest -= 1
                print(x, n)
            else:
                tmp = matrix[x][n]
        if n != x and matrix[x][n] > 0 and matrix[n][x] > 0 and matrix[x][n] != matrix[n][x] > 0:
            honest -= 1
            print(x, n)
        
print(honest)

Submission status: Wrong Answer

Solution code:

muzyun = 0
data = {}
num = int(input())
for i in range(num):
    words = int(input())
    for j in range(words):
        a, b = input().split(' ')
        if a not in data:
            data[a] = [b]
        else:
            data[a].append(b)
        #print(str(i+1) + ' ' + str(words) + ' ' + a + ' ' + b)

usotuki = 0
for i in data:
    a = sum(list(map(int, data[i])))
    if a != 0 or a != (num - 1):
        usotuki = usotuki + 1

print(num - usotuki)

Submission status: Wrong Answer

Solution code:
#ABC147 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
T = [[] for i in range(n)]
F = [[] for i in range(n)]
ans = [[] for i in range(n)]
for i in range(n):
    a = ni()
    for j in range(a):
        x,y=nm()
        if y==1:
            T[x-1].append(i)
        elif y==0:
            F[x-1].append(i)

for i,t in enumerate(T):
    for tt in t:
        ans[tt].append(True)

for i,f in enumerate(F):
    for ff in f:
        ans[ff].append(False)

aaaa=0
for aaa in ans:
    if all(aaa):
        aaaa+=1
print(aaaa)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = {}
for i in range(n):
    a = int(input())
    if a <= 0:
        continue
    xy[i] = {}
    for j in range(a):
        x, y = list(map(int, input().split()))
        xy[i][x-1] = y
# print(xy)
maxNumHonest = 0
# print(1 << n)
for pattern in range(1 << n):
    numHonest = 0
    for i in range(n):
        if pattern & (1 << i):
            numHonest += 1
    if numHonest <= maxNumHonest:
        continue
    isValid = True
    for i, statements in xy.items():
        isIHonest = bool((pattern & (1 << i)))
        for j, statement in statements.items():
            isJHonest = bool((pattern & (1 << j)))
            if isIHonest:
                if bool(statement) != isJHonest:
                    isValid = False
                    break
            else:
                if bool(statement) == isJHonest:
                    isValid = False
                    break
    if isValid:
        maxNumHonest = numHonest
print(maxNumHonest)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
def checkp(p):
    cnt = 0
    for j in range(n):
        if len(p[j]) == 0: # 言及なし
            cnt += 1
        elif 1 in p[j] and 0 in p[j]: # 矛盾
            return -1
        elif 1 in p[j]: # 正直者
            cnt += 1
    return cnt

ans = 0
for i in itertools.product([0, 1], repeat=n):
    p = [set() for _ in range(n)]
    for j in range(n):
    #for xyi in xy:
        xyj = xy[j]
        p[j].add(i[j])
        for xyk in xyj:
            #print(xyk)
            if i[j] == 0:
                p[xyk[0]-1].add(-xyk[1] + 1)
            else:
                p[xyk[0]-1].add(xyk[1])
    #print(i, p, checkp(p))
    ans = max(ans, checkp(p))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

n = int(input())
mat = np.ones((n, n))
for i in range(n):
    tmp_a = int(input())
    for j in range(tmp_a):
        tmp_x, tmp_y = map(int, input().split())
        if tmp_y == 0:
            mat[i][tmp_x-1] = 0
          
#bit全探索

ans = 0
for k in range(2**n):
    bit_list = [0] * n
    for l in range(n):
         if ((k >> l) & 1):
            bit_list[n-1-l] = 1
    
    mat_check = mat
    for m in range(n)[::-1]:
        if bit_list[m] == 0:
            mat_check = np.delete(mat_check, obj=m, axis=0)
            mat_check = np.delete(mat_check, obj=m, axis=1)
    if np.sum(mat_check) == sum(bit_list)**2:
        print(bit_list)
        if sum(bit_list)>=2:
            ans = sum(bit_list)
        elif sum(mat[m])==1:
            ans = sum(bit_list)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
for i in range(N):
    n = int(input())
    for j in range(n):
        y, z = map(int, input().split(' '))
        x.append((i+1, y, z))
num = 0
for i in range(2 ** N)[::-1]:
    for c in x:
        if (i >> c[0]-1) & 1 != (i >> c[1]-1) & c[2]:
            break
    else:
        p = 0
        for j in range(N):
            if (i >> j) & 1:
                p += 1
        num = max(num, p)
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
table = [[-1]*(N+1) for i in range(N+1)]
for i in range(1,N+1):
    A = int(input())
    for j in range(A):
        x,y = map(int,input().split())
        table[i][x] = y
#print(table)
# table[i][x] 人iが人xを正直者;1,真偽不明:0,未言及:-1

ans = 0
for i in range(2**N):

    # hito = [0]*N
    # for j in range(N):
    #     if i >> j & 1:
    #         hito[j] = 1
    # print(hito)

    flag = True
    cnt = 0
    for j in range(N):
        if i >> j & 1:
            cnt += 1
            for k in range(N):
                if table[j+1][k+1] != -1:
                    #print(table[j+1][k+1])


                    if table[j+1][k+1] ^ (i >> k):
                        # if j == 1 and k == 0:
                        #     print(i>>k)
                        #     print(table[j+1][k+1])
                        flag = False
                        #print(i,j,k)
    if flag:
        if cnt > ans:
            ans = cnt
print(ans)
# print(3 >> 0) # 3????
# print(1^3)

Submission status: Wrong Answer

Solution code:

n = int(input())
total = list()
good_person = list()
bad_person = list()
for i in range(1,n+1):
    t = int(input())
    A = list()
    for index in range(1,t+1):
        _input = input().split(" ")
        x = int(_input[0])
        y = int(_input[1])
        A.append((x, y))
    total.append(A)

for person in total:
    x = [x[0] for x in person]
    y = [y[1] for y in person]
    for index, a in enumerate(y):
        if a == 1:
            # good
            good_person.append(x[index])
        else:
            bad_person.append(x[index])
output = 0
# print(good_person)
# print(bad_person)
if sorted(good_person) == sorted(bad_person):
    output = 0
elif len(good_person) == 0:
    output = 1
elif len(good_person)< len(bad_person):
    output = 0
else:
    output = len(good_person) - len(bad_person)
print(output)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
ma = 0
a = []
li = []
if n == 1:
    print(1)
    exit()
for i in range(n):
    an = int(stdin.readline().rstrip())
    a.append(an)
    lis = [list(map(int,stdin.readline().rstrip().split())) for _ in range(an)]
    l = [2]*n
    for j in lis:
        l[j[0]-1] = j[1]
    li.append(l)
point = 0
for i in range(n):
    flag = 0
    for j in range(n):
        if li[i][j] == 1:
            for k in range(n):
                if (li[i][k] == 0 and li[j][k] == 1) or (li[i][k] == 1 and li[j][k] == 0):
                    flag = 1
        elif li[i][j] == 0:
            for k in range(n):
                if (li[i][k] == 1 and li[j][k] == 1) or (li[i][k] == 0 and li[j][k] == 0):
                    flag = 1
    if flag == 0:
        su = li[i].count(1)
        ma = max(su,ma)
print(ma)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = []

for i in range(N):
  A = int(input())
  tempList = []
  for j in range(A):
    tempList.append(input().split())
    lst.append(tempList)
    
truthList = []
for i in range(len(lst)):
  tempList = []
  for j in range(len(lst[i])):
    tempList2 = []
    if lst[i][j][1] == '1':
      tempList2.append(lst[i][j][0])
      tempList2.append(True)
      tempList.append(tempList2)
    else:
      tempList2.append(lst[i][j][0])
      tempList2.append(False)
      tempList.append(tempList2)

boolList = []
for i in range(len(truthList)):
  for j in range(len(truthList[i])):
    boolList.append(truthList[i][j][1])
    
honest = sum(boolList)
unkind = len(boolList) - sum(boolList)

if honest == unkind:
  print(0)
elif honest == N:
  print(N)
elif unkind == N:
  print(N-1)
else:
  print(honest)

Submission status: Wrong Answer

Solution code:
import numpy as np
n_person = int(input())
infomations_all = [[tuple(map(int, input().split())) for _2 in range(int(input()))] for _1 in range(n_person)]

table = np.array([[-1] * n_person for _ in range(n_person)])
for person, infomations_of_each_person in enumerate(infomations_all):
    for infomation in infomations_of_each_person:
        target, isHonest = infomation
        table[person][target - 1] = isHonest

ans = 0
for tf_bits in range(2 ** n_person):
    tf_table = []
    honests = 0
    for shifts, row in enumerate(table):
        if tf_bits >> shifts & 1:
            for i, num in enumerate(row):
                if not (bool(num) == bool(tf_bits >> i)):
                    break
            else:
                tf_table.append(row)
                honests += 1
                continue
            break
    for column in np.array(tf_table).T:
        if 0 in column and 1 in column:
            break
    else:
        if honests > ans:
            ans = honests

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
ans = 0
alls = True
for i in range(n):
    nn = int(input())
    for ii in range(nn):
        x, y = map(int, input().split())
        cnt = 0
        if y == 1:
            cnt += 1
            alls = False
        else:
            cnt -= 1
    if cnt >= 1:
        ans += 1
if alls == True:
    ans = n // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
l = list()
for n in range(N):
    a = int(input())
    tmp = list()
    for m in range(a):
        tmp.append([int(x) for x in input().split()])
    l.append(tmp)
honest = [1]*(N+1)
honest[0] = 0
for n in range(N-1):
    for m in l[n]:
        for k in range(n+1,N):
            for s in l[k]:
                if m[0] == s[0]:
                    if m[1] != s[1]:
                        honest[m[0]] = 0
for n in range(1,N+1):
    if honest[n] == 1:
        for m in l[n-1]:
            if m[1] == 0:
                honest[m[0]] = 0
print(np.sum(honest))

Submission status: Wrong Answer

Solution code:
import sys 

n = int(input())
Asgs = list()

def get_sgs(an):
    sgs = [list(map(int, input().split())) for i in range(an)]
    return sgs


for i in range(n):
    an = int(input())
    Asgs.append(get_sgs(an))

bits = [1] * n
end = False
# print(Asgs)
# sys.exit()
last_bits = [2] * n

cnt = 0
while cnt < 5:
    for i in range(n):
        
        # i人目の意見の個数
        for j in range(len(Asgs[i])):
            # bitsには正直者と登録されている人があるひと(正直者として登録されている)を不親切というなら
            if bits[i] == 1 and Asgs[i][j][1] == 0 and bits[Asgs[i][j][0]-1] ==1:
                
                #発言者もしくは発言対象者が偽
                bits[i] = 0
                # print(i, j)
            # 正直者とされている人が不親切とされてる人を正直者と言っている場合,発言者は不親切である。
            if bits[i] == 1 and bits[Asgs[i][j][0]-1] == 0 and Asgs[i][j][1] == 1:
                bits[i] = 0
                # print('mj11')
            
    if last_bits == bits:
        cnt += 1
    last_bits = bits
        
# print(bits)
print(sum(bits))

Submission status: Wrong Answer

Solution code:
N = int(input())
i_dic = {}
for n in range(N):
    ai = int(input())
    ai_list = []
    for i in range(ai):
        ai_list.append(input().split())
    i_dic[str(n+1)] = ai_list 



max_h = 0
for xx in i_dic.keys():
    hou_dic = {}
    num_h = 0
    h_list = [xx]
    hdid = [xx]
    # assume xx is honest
    raw = i_dic[xx]
    for j in raw:
        xij,yij = j
        hou_dic[xij] = yij
        if yij == '1':
            h_list.append(xij)
            
    for yy in h_list:
        if yy in hdid:
            pass
        else:
            raw = i_dic[yy]
            for j in raw:
                xij, yij = j
                if xij in hou_dic.keys():
                    if yij == hou_dic[xij]:
                        pass
                    else:
                        hou_dic[xij] = '0'
                        num_h = 0
                        break
                else:
                    hou_dic[xij] = yij            
                num_h += 1
    if max_h < num_h:
        max_h = num_h

print(max_h)          
            

#     for x in i_dic.keys():
#         raw = i_dic[x]
#         for j in raw:
#             xij, yij = j
#             if xij in hou_dic.keys():
#                 if yij == hou_dic[xij]:
#                     pass
#                 else:
#                     hou_dic[x] = '0'
#                     break
#             else:
#                 hou_dic[xij] == yij

Submission status: Wrong Answer

Solution code:
N = int(input())
Harray = []
for i in range(N):
    Aarray = []
    A = int(input())
    for j in range(A):
        xy = list(map(int,input().split()))
        Aarray.append(xy)
    Harray.append(Aarray)

carray = []

for Ai in Harray:
    honest = [Harray.index(Ai)]
    honestcon = [Ai]
    for ans in Ai:
        que = []
        if ans[1] == 1:
            honest.append(ans[0]-1)
            honestcon.append(Harray[ans[0]-1])
            que.append(ans[0]-1)
        while len(que) > 0:
            d = que[0]

            que.pop(0)
            
            e = 0
            for h in honestcon:
                for h2 in h:
                    if h2[1] == 1:
                        h3 = [h2[0], 0]
                    else:
                        h3 = [h2[0], 1]
                    if h3 in Harray[d]:
                        e = 1
            
            for h4 in honest:
                if [h4,0] in Harray[d]:
                    e = 1

            if e == 0:
                for ans2 in Harray[d]:
                    if (ans2[1] == 1) and (ans2[0]-1 not in honest):
                        que.append(ans2[0]-1)
            else:
                honest = []
                break
                    
    carray.append(len(honest))

print(max(carray))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
X=[]
Y=[]
for i in range(n):
    ai = int(input())
    A.append(ai)
    x_list=[]
    y_list=[]
    for j in range(ai):
        x,y = map(int, input().split())
        x_list.append(x)
        y_list.append(y)
    X.append(x_list)
    Y.append(y_list)



honest = []
for k in range(n):
    for j in range(len(Y[k])):
        if int(Y[k][j])==1:
            honest.append(X[k][j])



not_honest= []
for k in range(n):
    for j in range(len(Y[k])):
        if int(Y[k][j])==0:
            not_honest.append(X[k][j])


ans=[]
import math

for i in range(n):
    if (i+1) in honest:
        ans.append(i+1)
        if (i+1) in not_honest:
            ans.pop()
    if (i+1) not in honest and (i+1) not in not_honest:
        ans.append(i+1)
    if len(honest)==0:
        num=math.floor(len(ans)/2)


num=len(ans)

if len(honest)==0:
    num=math.floor(len(not_honest)/2)
print(num)


# print(A)
# print(X[0][1])
# print(Y)

Submission status: Wrong Answer

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

t = []
l = []
ans = 0
flag = 0
f = 1
for i in range(n):
  if i+1 not in t and i+1 not in l:
    t_ = [i+1]
  flag = 1
  while(flag == 1):
    flag = 0
    t__ = [z for z in t_]
    t_ = []
    for m in t__:
      for j, k in zip(x[m],y[m]):
        if k == 0:
          if j in t or j in t_:
            f = 0
            t = []
            l = []
            t_ = []
            break
          l.append(j)
        if k == 1:
          if j in l:
            f = 0
            t = []
            l = []
            t_ = []
            break
          if j not in t and j not in t_:
            t_.append(j)
            flag = 1
      if f == 0:
        flag = 0
        t_ = []
        break
    t.append(i+1)
    t.extend(t_)
  if f != 0:
    ans = max(ans,len(t))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x-1, y))
            # 人iは人xのことをyと言っている

    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        # 人jは正直者
                        good = False
                    elif not(bit & (1 << j)) and y == 1:
                        # 人jはうそつき
                        good = False
            else:
                # 人iはうそつき
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 1:
                        # 人jは正直者
                        good = False
                    elif not(bit & (1 << j)) and y == 0:
                        # 人jはうそつき
                        good = False
            if not(good):
                break
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
not_honest = 0
for i in range(0, N):
  Ai = int(input())
  honesty = []
  for y in range(0, Ai):
    xij, yij = [int(x) for x in input().split()]
    honesty.append(yij)
  if 0 in honesty:
    not_honest = not_honest + 1
print((N - not_honest))