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())
list = [list() for _ in range(N)]
if N == 1:
  print(1)
  exit()

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

ans = 0
for i in range(2**N):
    flg = False
    do = [0] * N
    for j in range(N):
      if ((i >> j) & 1):
        do[j] = 1
    P = [-1] * N
    for n in range(N):
      if flg:break
      for p in list[n]:
        if P[p[0]-1] == -1:
          if do[n] == 1:
            P[p[0]-1] = p[1]
          else:
            if p[1] == 1:
              P[p[0]-1] = 0
            else:
              P[p[0]-1] = 1
          if P[p[0]-1] != do[p[0]-1]:
            flg = True
        else:
          if do[n] == 1 and P[p[0]-1] != p[1]:
            flg = True
    if flg:
      continue
    ans = max(ans,sum(do))
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2 << (n-1)):
    bn = str(bin(i))[2:].zfill(n)
    cnt = 0
    for j in range(1,n+1):
        if bn[j-1] == '0':
            continue
        for x,y in people[j].items():
            if bn[x-1] != str(y):
                break
            if y == 0:
                continue
            for xx,yy in people[x].items():
                if bn[xx-1] != str(yy):
                    break
            else:
                continue
            break

        else :
            cnt += 1
    if cnt > ans:
        ans = cnt

print(ans)

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):
  t.append(i+1)
  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.extend(t_)
  if f != 0:
    ans = max(ans,len(t))
  remain = list(set(range(1,n+1))-set(t)-set(l))
  if len(remain)>0:
    T = [z for z in t]
    L = [z for z in l]
    for u in remain:
      t.append(u)
      t_ = [u]
      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_ = []
            t = [z for z in T]
            l = [z for z in L]
            break
        t.extend(t_) 
      if f != 0:
        ans = max(ans,len(t))
        T = [z for z in t]
        L = [z for z in l]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
N=int(input())
box = [[1]*N for i in range(N)]

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

trueor=[0]*N
for i,a in enumerate(box):
  flag=True
  for j,t in enumerate(a):
    if i==j:
      continue
    else:
      if t==1 and box[j][i]==0:
        flag=False
  if flag:
    trueor[i]=1

for i,a in enumerate(box):
  flag=True
  for j,t in enumerate(a):
    if i==j:
      continue
    else:
      if t==0 and trueor[j]==1:
        flag=False
  if not flag:
    trueor[i]=0
print(sum(trueor))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


n = int(input())
a_dict = dict()
ans = 0

for i in range(n):
    a = int(input())
    a_dict[i+1] = [list(map(int, input().split())) for _ in range(a)]

for idx in range(n):
    ng = False
    tmp = 0
    r_dict = defaultdict(lambda: -1)
    for k in a_dict.keys():
        if ng: break
        a_list = a_dict[k]
        for itm in a_list:
            # print(k,itm)
            if (itm[0] == idx+1 and itm[1] == 0) or (r_dict[itm[0]] != -1 and r_dict[itm[0]] != itm[1]):
                ng = True
                break
            else:
                r_dict[itm[0]] = itm[1]
        else:
            tmp += 1
    else:
        ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

x_list = []
y_list = []
Group = []
A_list = []

Group_1 = 'Group_1'
Group_2 = 'Group_2'

for n in range(N):
    A = int(input())
    A_list.append(A)
    Group.append('none')
    x = []
    y = []
    for a in range(A):
        x_tmp, y_tmp = map(int, input().split())
        x.append(x_tmp)
        y.append(y_tmp)
    x_list.append(x)
    y_list.append(y)

flag = False

'''
for i in range(N):
    for A_list_i in range(A_list[i]):
'''        



for i in range(N):
    for a_list in range(A_list[i]):
        if y_list[i][a_list] == 1:
            if Group[i] != 'false' and Group[x_list[i][a_list]-1] != 'false':
                Group[i] = 'true'
                Group[x_list[i][a_list]-1] = 'true'
            elif Group[i] != 'true' and Group[x_list[i][a_list]-1] != 'true':
                Group[i] = 'false'
                Group[x_list[i][a_list]-1] = 'false'
            elif Group[i] == 'true' and Group[x_list[i][a_list]-1] == 'false':
                flag = True
                break
            elif Group[i] == 'false' and Group[x_list[i][a_list]-1] == 'true':
                flag = True
                break
        if y_list[i][a_list] == 0:
            if Group[i] != 'true' and Group[x_list[i][a_list]-1] != 'false':
                Group[i] = 'false'
                Group[x_list[i][a_list]-1] = 'true'
            elif Group[i] != 'false' and Group[x_list[i][a_list]-1] != 'true':
                Group[i] = 'true'
                Group[x_list[i][a_list]-1] = 'false'                   
            elif Group[i] == 'true' and Group[x_list[i][a_list]-1] == 'true':
                flag = True
                break
            elif Group[i] == 'false' and Group[x_list[i][a_list]-1] == 'false':
                flag = True
                break


if flag:
    print(0)
else:
    print(max(Group.count('true'), Group.count('false')))

Submission status: Wrong Answer

Solution code:
def f():
    N = int(input())
    A = []
    
    for n in range(N):
        templist = []
        for a in range(int(input())):
            templist.append(list(map(int, input().split())))
        A.append(templist)
    
    # print(A)
    
    maxlen = len(str(bin(2**len(A)-1).replace('0b','')))
    for j in reversed((range(2**len(A)))):
        tempb = str(bin(j).replace('0b',''))
        for i in range(maxlen - len(tempb)):
            tempb = '0'+tempb
        # ここでパターン仮置き確定
        tempj = list(map(int, list(tempb)))
        counter = 0
        for jj in range(len(tempj)):
            if tempj[jj] == 1: # 正直者の場合
                # 証言の数だけループを回す
                shocounter = 0
                for s in range(len(A[jj])):
                    if tempj[A[jj][s][0]-1] != A[jj][s][1]:# 本当は違う
                        break
                    else:
                        shocounter += 1
                if shocounter == len(A[jj]):
                    counter += 1
            else:
                # 証言の数だけループを回す
                shocounter = 0
                for s in range(len(A[jj])):
                    if tempj[A[jj][s][0]-1] == A[jj][s][1]:# 本当はあってる
                        break
                    else:
                        shocounter += 1
                if shocounter == len(A[jj]):
                    counter += 1
        if counter == len(A):
            return print(tempj.count(1))
            
    return print(tempj.count(1))
    
f()

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

dicts = {i+1:{}  for i in range(N)}
un_dicts={i+1:{}  for i in range(N)}
for i in range(1,N+1):
    num = one_int()
    bits = ["0" for k in range(N)]
    un_bits = ["1" for k in range(N)]
    
    bits[int(i-1)]="1"
    un_bits[int(i-1)]="0"

    
    for j in range(num):
        hito, singi = two_int()
        bits[hito-1] = str(singi)
        
        if singi==1:
            un_bits[hito-1] = str(0)
        else:
            un_bits[hito-1] = str(1)
    
    dicts[i] = "".join(bits)
    un_dicts[i] = "".join(un_bits)



users = [j+1 for j in range(N)]
max_n=0
# 信じる人のループ
for i in dicts:
    all_syougens=[]
    all_or = 0
    old=0
    flg=False
    #信じる人の証言取得
    syougen = list(map(int, list(dicts[i])))
    
    # 信じる人の証言を各人の証言に適応
    count = 0
    
    aaaa = [[] for j in range(N)]
    for u,s in zip(users,syougen):
        si = dicts[u]
        index=0
        #信じる人がうそつきだといったら反転
        if s==0:
            si = un_dicts[u]
        for k in list(si):
            aaaa[index].append(k)
            index+=1
    flg=True
    for i in aaaa:
        if len(set(i)) >1:
            flg=False
            break
        else:
            if len(set(i))==1 and list(set(i))[0]=="1":
                count+=1 
    if flg:
        if count >= max_n:
            max_n = count
print(max_n)

Submission status: Wrong Answer

Solution code:
N = int(input())

answers = [[-1 for i in range(N)] for j in range(N)]


def mujunChecker(row1, row2):
    flag = True
    for l in range(len(row1)):
        if row1[l] == 1 and row2[l] == 0:
            flag =  False
        elif row1[l] == 0 and row2[l] == 1:
            flag = False
            
    return flag
    
for n in range(N):
    num_t = int(input())
    for t in range(num_t):
        x, y = [int(i) for i in input().split()]
        answers[n][x-1] = y

flag = True

for row in answers:
    if 1 in row:
        flag = False
        break

if flag:
    print(N // 2)
else :
    counter = 0
    for row in range(len(answers)):
        for column in range(len(answers[row])):
            if answers[row][column] == 1:
                if mujunChecker(answers[row], answers[column]):
                    # print(answers[row], answers[column])
                    counter += 1

    print(counter)

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 == 1:
                        # 人jは正直者
                        pass
                    elif not(bit & (1 << j)) and y == 0:
                        # 人jはうそつき
                        pass
                    else:
                        good = False
                        break
            else:
                # 人iはうそつき
                for j, y in G[i]:
                    if (bit & (1 << j)) and y == 0:
                        # 人jは正直者
                        pass
                    elif not(bit & (1 << j)) and y == 1:
                        # 人jはうそつき
                        pass
                    else:
                        good = False
                        break
            if not(good):
                break
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

all_l = []
for n in range(N):
  A = int(input())
  l = ["-"]*N
  l[n]=str(1)
  for a in range(A):
    x, y = map(int, input().split())
    l[x-1]=str(y)
  all_l.append("".join(l))
  
c = collections.Counter(all_l)

if len(c)>2:
  print(0)
else:
  print(max(c.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
l = [[1]*N for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    x, y = map(int,input().split())
    l[i][x-1] = y
    l[i][i] = 1
cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if l[i][j] != l[j][i]:
      cnt += 1
    if l[i][j] == l[j][i] and l[i][j]==0:
      cnt += 1
print(N-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
remarks = []
for i in range(N):
    w = []
    for j in range(int(input())):
        w.append(list(map(int, input().split())))
    remarks.append(w)

def power2(n):
    if n == 1:
        return [[1], [0]]
    res = []
    for l in power2(n-1):
        res.append([1] + l)
        res.append([0] + l)
    return res

ans = 0
patterns = power2(N)
for p in patterns:
    flag = True
    for i, remark in enumerate(remarks):
        if p[i] == 0: #不親切者の発言を無視
            continue
        for w in remark:
            if p[w[0]-1] != w[1]: #発言の矛盾を判定:
                flag = False 
                break
            # print(w)
    if flag: #すべての発言で矛盾がなかった場合
        ans = max(ans, p.count(1))
        break

print(ans)

Submission status: Wrong Answer

Solution code:
# C問題

from itertools import combinations
import numpy as np
N = int(input())

A = []
x = []
y = []
for i in range(N):
	# 人iの証言を格納する
	Ai = int(input())
	A.append(Ai)
	x.append([])
	y.append([])
	for j in range(Ai):
		xyij = input().split(" ")
		x[i].append(int(xyij[0]) - 1)
		y[i].append(int(xyij[1]))

def judge_contradiction(honest_index, N, A, x, y):
	# 大丈夫ならTrue、矛盾ならFalse
	all_people_judge = np.zeros(N, dtype="int")
	all_people_judge[:] = -1
	for i in honest_index:
		all_people_judge[i] = 1
	for ind in honest_index:
		# 人indは正直者。
		# この人の証言をもとに、all_people_judgeを完成させる
		for i in range(A[ind]):
			# 証言： 人x[ind][i]は、y[ind][i]である
			target, testimony = x[ind][i], y[ind][i]
			if all_people_judge[target] == -1:
				all_people_judge[target] = testimony
				continue
			elif all_people_judge[target] == testimony:
				continue
			else:
				# 矛盾が発生！
				return False
	# all_people_judgeで正直者と判定された人が、honest_indexでもそうなっているか判定
	for i in range(N):
		if all_people_judge[i] == 1:
			if np.any(np.array(honest_index) == i):
				continue
			else:
				return False
	return True

def doit(N, A, x, y):
	for numHonest in range(N, 0-1, -1):
		# numHonest 人が正直者であるとき
		for honest_index in combinations(np.arange(N), numHonest):
			# N人の正直者は、honest_indexに記載されたN人である
			# それで矛盾が生じないか、確かめる
			# import pdb; pdb.set_trace()
			if judge_contradiction(honest_index, N, A, x, y) == True:
				return numHonest
			else:
				continue
	return "hey"

doit(N, A, x, y)

Submission status: Wrong Answer

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

ans = 0
if len(sh) == 0:
    print(1)
else:
    for i in range(len(sh)):
        if i == sh[sh[i]]:
            ans += 1
    print(ans)

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
def my_shift(i,k):
    return int(str(bin(i))[-1]) if k == 0 else i>>k
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 table[j+1][k+1] ^ my_shift(i,k):
                        # if j == 1 and k == 0:
                        #     print(i>>k)
                        #     print(my_shift(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????

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        xy.append(list(map(int, input().split())))
    l.append(xy)
m = []
for i in l:
    w = [""] * n
    for j, k in i:
        w[j-1] = k
    m.append(w)

ad = 0
ans = [1] * n
for i in range(n):
    for j in range(n):
        if m[i][j] == 0 and m[j][i] == 1:
            ans[i] = 0
        elif m[i][j] == 1 and m[j][i] == 0:
            ans[i] = 0
        elif m[i][j] == 1 and ans[j] == 0 or m[i][j] == 0 and ans[j] == 1:
            ans[i] = 0
        elif m[i][j] == 1 and m[j][i] == 1:
            ans[i] = 1
            ans[j] = 1

print(sum(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


n = int(input())
a_dict = dict()
r_dict = defaultdict(lambda: -1)
ans = 0

for i in range(n):
    a = int(input())
    a_dict[i+1] = [list(map(int, input().split())) for _ in range(a)]

for idx in range(n):
    ng = False
    tmp = 0
    for k in a_dict.keys():
        if ng: break
        a_list = a_dict[k]
        for itm in a_list:
            # print(k,itm)
            if (itm[0] == idx+1 and itm[1] == 0) or (r_dict[itm[0]] != -1 and r_dict[itm[0]] != itm[1]):
                ng = True
                break
            else:
                r_dict[itm[0]] = itm[1]
        else:
            tmp += 1
    else:
        ans = max(ans, tmp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
Adj = [[-1]*n for _ in range(n)]

for i in range(n):
    ai = int(input())
    for j in range(ai):
        xij,yij = map(int, input().split( ))
        xij -= 1
        Adj[i][xij] = yij###==ってなんぞ
#print(Adj)
ans = 0

bt = 1<<n

for b in range(bt):#全探索
    flag = True
    tmp = 0
    for i in range(n):
        for j in range(n):
            if Adj[i][j]>=0:
                if ((b>>i) &1) and ((Adj[i][j]==0) ^ ((b>>j) &1)):#正直者の答えが矛盾,醜いがあとでビット演算子確認
                    flag = False
                    break
        if not flag:
            break
    if flag:
        for t in range(n):
            tmp += (b>>t)&1
            #print("test",b,tmp,flag)
    ans = max(tmp, ans)
    #print(b,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product

# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    N = int(input())
    grid = [[None for _ in range(N)] for i in range(N)]
    for i in range(N):
        a = int(input())
        for _ in range(a):
            x, y = list(map(int, input().split()))
            grid[i][x-1] = y
    res = 0
    for p in product([0, 1], repeat=N):
        flag = True
        p = list(p)
        for i in range(N):
            for j in range(N):
                if p[i] == 1:
                    if grid[i][j] == p[j]:
                        continue
                    flag = False
                    break
            if flag:
                continue
            break
        if flag:
            res = max(res, sum(p))
    print(res)
    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = ['']

res = []

for _ in range(N):
    A = int(input())
    s = []
    for _ in range(A):
        s.append(list(map(int, input().split())))
    S.append(s)

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        else:
            l_list.append(t)
            # for s in S[t]:
            #     if s[1] == 1:
            #         if s[0] in h_list:
            #             break
            #         l_list.append(s[0])
            #     else:
            #         if s[0] in l_list:
            #             break
            #         h_list.append(s[0])
            # else:
            #     continue
            # break
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)

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)

Submission status: Wrong Answer

Solution code:
n = int(input())
humanlist = []
a = []
unkind = []
for l in range(n):
    s = int(input())
    a.append(s)
    for i in range(s):
        humanlist.append(list(map(int, input().split())))
    unkind.append(humanlist)
    humanlist = []
truelist = []
falselist = []
deffalselist = []
deffalselist = [0]*n
truelist = [0]*n
falselist = [0]*n
for i in range(n):
    truelist[i] = 1

    truelen = 1
    truelen1 = 0
    while True:
        if truelen == truelen1:
            break
        truelen = truelen1
        nowtrue = unkind[i]
        for k in range(len(nowtrue)):
            if nowtrue[k][1] == 1:
                truelist[nowtrue[k][0]-1] = 1
            else:
                falselist[nowtrue[k][0]-1] = 1
        truelen1 = len([i for i in truelist if i == 1])
    for j in range(n):
        if falselist[j] == 1 and truelist[j] == 1:
            deffalselist[i] = 1
        elif falselist[j] == 0 and truelist[j] == 0:
            truelist[j] = 1
            truelen = 1
            while True:
                if truelen == truelen1:
                    break
                truelen = truelen1
                nowtrue = unkind[i]
                for k in range(len(nowtrue)):
                    if nowtrue[k][1] == 1:
                        truelist[nowtrue[k][0]-1] = 1
                    else:
                        falselist[nowtrue[k][0]-1] = 1
                truelen1 = len([i for i in truelist if i == 1])
            for h in range(n):
                if falselist[h] == 1 and truelist[h] == 1:
                    deffalselist[h] = 1
    falselist = [0]*n
    truelist = [0]*n
print(n-len([i for i in deffalselist if i == 1]))

Submission status: Wrong Answer

Solution code:

n=int(input())
a=[0]*n
g=[[0]*n for _ in range(n)]
for i in range(n):
    a[i]=int(input())
    for j in range(a[i]):
        x,y=map(int,input().split())
        g[i][x-1]=y
count=0
for i in range(n):
    for j in range(n):
        if i==j:
            break
        else:
            if g[i][j]==0 and g[j][i]==0:
                count+=1
print(count)

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"])
  hset=set(range(n))-sset
  print(sset,hset)
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
    
  if len(jjj&sset) or len(kkk&hset) :
    continue
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)

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

anslit = []

for n in range(N):
    mylist = [-1 for i in range(N)]
    A = int(input())
    for a in range(A):
        x, y = map(int, input().split())
        mylist[x-1] = y
    mylist[n] = 1   
    anslit += [mylist]
#print(anslit)

mylist2 = [0 for i in range(N)]

for i in range(len(anslit)-1):
    for j in range(i+1, len(anslit)):
        #正直アンド正直
        uso1lsit = [0 for n in range(N)]
        for u,x in enumerate(anslit[i]):
            if x == 0:
                uso1lsit[u] = 1
            else:
                uso1lsit[u] = 0
        
        uso2list = [0 for n in range(N)]
        for u,x in enumerate(anslit[j]):
            if x == 0:
                uso2list[u] = 1
            else:
                uso2list[u] = 0
        #print(uso1lsit,uso2list)
        if anslit[i] == anslit[j]:
            mylist2[i] = 1
            mylist2[j] = 1
        #正直アンド嘘
        elif anslit[i] == uso2list:
            mylist2[i] = 1
        elif uso1lsit == anslit[j]:
            mylist2[j] = 1
        #正 

print(sum(mylist2))

Submission status: Wrong Answer

Solution code:
n = int(input())
honest = {}
honest1 = {}
for i in range(n):
    honest1[i+1] = []
dic = {}
for i in range(n):
    n1 = int(input())
    for j in range(n1):
        a, b = map(int, input().split())
        honest1[a].append(b)
        if i+1 in dic:
            dic[i+1].append([a, b])
        else:
            dic[i+1] = [[a, b]]

for i in honest1:
    if honest1[i].count(1) > honest1[i].count(0):
        honest[i] = True
        honest1[i] = False
    else:
        honest[i] = False
        honest1[i] = False
for i in dic:
    if honest[i]:
        for j in dic[i]:
            honest[j[0]] = True if j[1] == 1 else False
            honest1[j[0]] = True
c = 0
for i in honest:
    if honest[i]:
        c += 1
if c > 0:
    for i in dic:
        if not honest[i]:
            f = 0
            for j in dic[i]:
                if j[1] != honest[j[0]]:
                    if honest1[j[0]]:
                        f = 1
                        break
            if f == 0:
                honest[i] = True
else:
    for i in dic:
        if not honest[i]:
            f = 0
            for j in dic[i]:
                if j[1] != honest[j[0]]:
                    if not honest[j[0]]:
                        f1 = 0
                        for k in dic[j[0]]:
                            if k[1] != honest[k[0]]:
                                f1 = 1
                                break
                        if f1 == 0:
                            honest[j[0]] = True
                    else:
                        f = 1
                        break

    c = 0
    for i in honest:
        if honest[i]:
            c += 1
    print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

def acinput():
    return list(map(int, input().split(" ")))


def chk(x,d):
    for l,xx in enumerate(x):
        if xx==1:
            for dd in d[l]:
                #print(dd)
                #print(x)
                if dd[1]==1 and x[dd[0]-1]==0:
                    return False
                if dd[1]==0 and x[dd[0]-1]==1:
                    return False
    return True


N=int(input())

d=[]
for k in range(N):
    aa=int(input())
    print(aa)
    d.append([])
    for j in range(aa):
        d[-1].append(acinput())


#print(d)
res=0

for x in range(2**N):
    x=list(map(int,list(bin(x)[2:].zfill(N))))
    #print(x)
    if chk(x,d):
        res=sum(x)
    
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = ['']

res = []

for _ in range(N):
    A = int(input())
    s = []
    for _ in range(A):
        s.append(list(map(int, input().split())))
    S.append(s)

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        # else:
        #     l_list.append(t)
        #     for s in S[t]:
        #         if s[1] == 1:
        #             if s[0] in h_list:
        #                 break
        #             l_list.append(s[0])
        #         else:
        #             if s[0] in l_list:
        #                 break
        #             h_list.append(s[0])
        #     else:
        #         continue
        #     break
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)