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())
a = []
xy = [[] for i in range(n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        xy[i].append(list(map(int, input().split())))
ans = 0
for i in range(2**n):
    tf = [False for j in range(n)]
    for j in range(n):
        if (i>>j)&1:
            tf[j] = True
    flag = False
    for j in range(n):
        for k in range(a[j]):
            if tf[j]:
                if xy[j][k][1] != tf[xy[j][k][0]-1]:
                    flag = True
                    break
            else:
                if xy[j][k][1] == tf[xy[j][k][0]-1]:
                    flag = True
                    break
        if flag:
            break
    else:
        ans = max(ans, tf.count(True))
print(ans)

Submission status: Wrong Answer

Solution code:
#C - HonestOrUnkind2
N = int(input())
A = []
X = []
Y = []
for _ in range(N):
    a = int(input())
    A.append(a)
    box_x = []
    box_y = []
    for _ in range(a):
        x,y = map(int,input().split())
        box_x.append(x)
        box_y.append(y)
    X.append(box_x)
    Y.append(box_y)
print(A,X,Y)

person = [2]*N

maxim = 0
for i in range(1<<N):
    c_person = person.copy()
    honest = 0
    for j in range(N):
        mask = 1<<j
        if mask&i != 0:
            c_person[j] = 1
        else:
            c_person[j] = 0
    #正直者かどうかの仮定
    for k,l in enumerate(c_person):
        #kが正直者のとき
        if l == 1:
            #kの証言を判定
            for m,n in zip(X[k],Y[k]):
                #矛盾があるなら honest = 0でbreak
                if c_person[m-1] != n:
                    honest = 0
                    break
            else:
                honest = sum(c_person)
                continue
            break
    maxim = max(maxim,honest)
                
print(maxim)

Submission status: Wrong Answer

Solution code:
N=int(input())
res=[[[],[]] for _ in range(N)]

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

opp=[]
for n in range(N):
    if len(res[n][0])*len(res[n][1])!=0:
        for s in res[n][0]:
            for t in res[n][1]:
                opp.append((s,t))

#print(opp)

import sys
ans_a,ans_b=[],[]

for v in opp:
    v0,v1=min(v[0],v[1]),max(v[0],v[1])
    
    if v0 in ans_a:
        if v1 in ans_b:
            pass
        else:
            if v0 in ans_b:
                print(0)
                sys.exit()
            else:
                ans_b.append(v1)
    else:
        if v1 in ans_b:
            if v0 in ans_b:
                print(0)
                sys.exit()
            else:
                ans_a.append(v0)
        else:
            if v0 in ans_b:
                ans_a.append(v1)
            else:
                ans_a.append(v0)
                ans_b.append(v1)
    #print(ans_a)
    #print(ans_b)
    #print()
    
print(max(len(ans_a),len(ans_b)))

Submission status: Wrong Answer

Solution code:
N=int(input())
T=[[] for _ in range(N)]
for i in range(N):
  n=int(input())
  for j in range(n):
    T[i].append(tuple(map(int,input().split())))
ans=0
for i in range(N**2):
  true,t,f=set(),set(),set()
  for j in range(N):
    if i>>j&1:
      true.add(j+1)
      for a,b in T[j]:
        if b:
          t.add(a)
        else:
          f.add(a)
  if t<=true and not(f&true):
    ans=max(ans,len(true))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
syougen=[[] for x 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())
        syougen[i].append([x,y])

ans=0

for katei in range(2**n-1):
    hantei=katei
    muzyun=False
    for i in range(1,n+1):
        if hantei & 1:
            for j in range(len(syougen[i])):
                taisyou=syougen[i][j][0]
                if katei>>taisyou-1 & 1 != syougen[i][j][1]:
                    muzyun=True
                    break
        hantei>>=1
    if muzyun==False:
        ans=max(bin(katei).count("1"),ans)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
h = [[] for _ in range(n)]
u = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        if y == 1:
            h[i].append(x)
        elif y == 0:
            u[i].append(x)

ans = 0
for i in range(2**n):
    hs, us = [], []
    honest, unkind = [], []
    for j in range(n):
        if i & (1 << j):
            hs.extend(h[j])
            us.extend(u[j])
            honest.append(j+1)
        else:
            unkind.append(j+1)
    hs.sort()
    us.sort()
    if not hs <= honest:
        continue
    if not us <= unkind:
        continue
    ans = max(ans, len(honest))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

print(lis)

ans=-1
for binary in itertools.product([1,0],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==1:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
    if check==0:
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

ans=-1
for binary in itertools.product([1,0],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==1:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
        else:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]==lis[i][j][1]:
                    check+=1
    if check==0:
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
print(15)

Submission status: Wrong Answer

Solution code:
print(0)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

ans=0
for binary in itertools.product([1,0],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==1:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
        else:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]==lis[i][j][1]:
                    check+=1
    if check==0:
        print(binary)
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

#print(lis)
ans=0
for binary in itertools.product([0,1],repeat=n):
    check=0
    for i in range(n):
        #print("bi",binary[i])
        if binary[i]==1:
            for j in range(len(lis[i])):
                #print(binary[lis[i][j][0]],lis[i][j][1])
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
        else:
            for j in range(len(lis[i])):
                #print(binary[lis[i][j][0]],lis[i][j][1])
                if binary[lis[i][j][0]]==lis[i][j][1]:
                    check+=1
    if check==0:
        #print(binary)
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

ans=0
for binary in itertools.product([0,1],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==0:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
        else:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]==lis[i][j][1]:
                    check+=1
    if check==0:
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())

lis=[]
for i in range(n):
    ai=int(input())
    lisi=[]
    for _ in range(ai):
        xi,yi=map(int,input().split())
        lisi.append([xi-1,yi])
    lis.append(lisi)

ans=0
for binary in itertools.product([0,1],repeat=n):
    check=0
    for i in range(n):
        if binary[i]==1:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]!=lis[i][j][1]:
                    check+=1
        else:
            for j in range(len(lis[i])):
                if binary[lis[i][j][0]]==lis[i][j][1]:
                    check+=1
    if check==0:
        ans=max(ans,sum(binary))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
L = []
for i in range(N):
  a = int(input())
  A.append(a)
  tmp = []
  for i in range(a):
    tmp.append(list(map(int, input().split())))
  L.append(tmp)

ans = 0
for i in range(1, 2**N):
  tmp = [-1] * N
  flag = True
  d = []
  for j in range(N):
    if (i>>j) & 1:
      tmp[j] = 1
      l = L[j]
      for k in range(len(L[j])):
        p, t = l[k][0], l[k][1]
        if tmp[p-1] < 0:
          tmp[p-1] = t
        elif tmp[p-1] != t:
          flag = False
          break
      if flag == False:
        break
    else:
      tmp[j] = 0
      d.append(j)
  for m in range(len(d)):
    n = d[m]
    if tmp[n] == 1:
      flag = False
      break
  if flag:
    ans = max(ans, tmp.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
L = []
for i in range(N):
  a = int(input())
  A.append(a)
  tmp = []
  for i in range(a):
    tmp.append(list(map(int, input().split())))
  L.append(tmp)

ans = 0
for i in range(1, 2**N):
  tmp = [-1] * N
  flag = True
  d = []
  for j in range(N):
    if (i>>j) & 1:
      tmp[j] = 1
      l = L[j]
      for k in range(len(L[j])):
        p, t = l[k][0], l[k][1]
        if tmp[p-1] < 0:
          tmp[p-1] = t
        elif tmp[p-1] != t:
          flag = False
          break
      if flag == False:
        break
    else:
      d.append(j)
  for m in range(len(d)):
    n = d[m]
    if tmp[n] == 1:
      flag = False
  if flag:
    ans = max(ans, tmp.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A_lst = [0] * N
    xy_lst = [[]] * N
    ans = 0

    for i in range(N):  # 入力
        A = int(input())
        A_lst[i] = A
        xy_lst[i] = [[]] * A

        for j in range(A):
            x, y = map(int, input().split())
            xy_lst[i][j] = [x, y]  # 3次元配列 i人目のj番目の証言の[x,y]

    for i in range(2 ** N):  # ビット全探索
        honest_unkind = [0] * N
        flag = True

        for j in range(N):  # 1つ状態を決める
            if (i >> j) & 1 == 1:
                honest_unkind[j] = 1  # 1:honest, 0:unkind

        for j in range(N):  # 1人ずつ証言を検証する
            for k in range(A_lst[j]):  # 各人の証言がk個
                if honest_unkind[j] == 1:  # j番目の人がhonestだったら
                    if xy_lst[j][k][1] == 0 and honest_unkind[xy_lst[j][k][0] - 1] == 1:
                        flag = False  # 矛盾したら終了
                        break
                    if xy_lst[j][k][1] == 1 and honest_unkind[xy_lst[j][k][0] - 1] == 0:
                        flag = False
                        break
                if honest_unkind[j] == 0:  # j番目の人がunkindだったら
                    if xy_lst[j][k][1] == 0 and honest_unkind[xy_lst[j][k][0] - 1] == 0:
                        flag = False
                        break
                    if xy_lst[j][k][1] == 1 and honest_unkind[xy_lst[j][k][0] - 1] == 1:
                        flag = False
                        break

        if flag == True:  # 全員の証言が矛盾しなかった場合
            cnt = sum(honest_unkind)
            if cnt > ans:
                ans = cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

cor,fal = [-1]*n,[-1]*n
for i in range(n):
    a = int(input())
    for j in range(a):
        b,c = map(int,input().split())
        if c == 1:
            cor[b-1] = 1
        else:
            fal[b-1] = 1
#print(cor)
#print(fal)
cnt = 0
for i in range(n):
    if cor[i] == 1 and fal[i] == 1:
        cnt +=1
print(n-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append([[int(x) for x in input().split()] for _ in range(a)])
ans = 0
for i in range(2**N):
    indexes = [j for j in range(N) if i & (1 << j)]
    expects = set([j + 1 for j in indexes])
    alist = [A[j] for j in indexes]
    valid = True
    honests = set()
    liars = set()
    for a in alist:
        for (index, is_honest) in a:
            if is_honest == 1:
                honests.add(index)
            else:
                liars.add(index)
    if not honests & liars:
        if honests & expects:
            ans = max(ans, len(honests))
        elif liars & expects:
            ans = max(ans, 1)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
Y = [[] for _ in range(N)]

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

cnt = []

for i in range(2**N):
    ans = [[] for _ in range(N)]
    ind = bin(i)[2:]
    ind_2 = '0'*(N-len(ind)) + ind
    for n in range(N):
        if ind_2[n] == '1':
            for s in range(len(Y[n])):
                ans[Y[n][s][0]-1].append(Y[n][s][1])

    for a in ans:
        d = 0
        s = ''
        if len(a) == 0:
            continue
        if len(a) > 1:
            break
        elif a[0] != int(ind_2[d]):
            break
    else:
        cnt.append(sum([int(ind_2[k]) for k in range(len(ind_2))]))

print(max(cnt))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def count(zerone):
    one = 0
    cnt = 0
    for i in range(N):
        flag = True
        if zerone[i] == 1:
            one += 1
            for j in range(len(A[i])):
                if A[i][j][1] != zerone[A[i][j][0]-1]:
                    flag = False
                    break
        else:
            for j in range(len(A[i])):
                if A[i][j][1] == zerone[A[i][j][0]-1]:
                    flag = False
                    break
        if flag:
            cnt += 1
    if cnt == N:
        return one
    else:
        return 0

# bit列の列挙
def dfs(bits):
    if len(bits) == N:
        return count(bits)
    res = 0
    for i in range(2):
        bits.append(i)
        res = max(res, dfs(bits))
        bits.pop()
    return res

# main
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        A[i].append([int(x) for x in input().split()])

ans = dfs([])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [False]*n
ls = [0]*n
param_list = [0]*2**n
for i in range(2**(n-1)):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i] = l 
#1print(param_list)
 
for i in range(2**(n-1)):
    l = [True]+[False]*(n-1)
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i+2**(n-1)] = l 
#print()
#print(param_list)
 
for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in param_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    #print(2)
                    pass
            else:
              new_param.append(d)
                #if d[a-1] is b:
                    #print(3)
                    #pass
                #else:
                    #print(4)
                    #new_param.append(d)
                    #pass
            
        param_list = new_param
        #print(param_list)
            
ans = 0    
for d in param_list:
    ans = max(ans,d.count(True))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [False]*n
ls = [0]*n
param_list = [0]*2**n
for i in range(2**(n-1)):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i] = l 
#1print(param_list)
 
for i in range(2**(n-1)):
    l = [True]+[False]*(n-1)
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i+2**(n-1)] = l 
#print()
#print(param_list)
 
for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in param_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    #print(2)
                    pass
            #else:
                #if d[a-1] is b:
                    #print(3)
                    #pass
                #else:
                    #print(4)
                    #new_param.append(d)
                    #pass
            
        param_list = new_param
        #print(param_list)
            
ans = 0    
for d in param_list:
    ans = max(ans,d.count(True))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [False]*n
ls = [0]*n
param_list = [0]*2**n
for i in range(2**(n-1)):
    l = [False]*n
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i] = l 
#1print(param_list)

for i in range(2**(n-1)):
    l = [True]+[False]*(n-1)
    for id_r, row in enumerate(ls):
        if i & id_r >0:
            l[id_r] = True
    param_list[i+2**(n-1)] = l 
#print()
#print(param_list)

for i in range(n):
    A = int(input())
    for k in range(A):
        a,b = map(int, input().split())
        b = (1==b)
        new_param =[]
        for d in param_list:
            if d[i]:
                if d[a-1] == b:
                    new_param.append(d)
                    pass
                else:
                    #print(2)
                    pass
            else:
                if d[a-1] is b:
                    #print(3)
                    pass
                else:
                    #print(4)
                    new_param.append(d)
                    pass
            
        param_list = new_param
        #print(param_list)
            
ans = 0    
for d in param_list:
    ans = max(ans,d.count(True))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

statements=[]
honests=[0]
for i in range(N):
  statement=[]
  A=int(input())
  for j in range(A):
    x,y=map(int,input().split(' '))
    statement.append([x-1,y]) 
  statements.append(statement)

#print(statements)

for honest in range(1<<N):
  flag=True
  #print("honest {:03b}".format(honest))
  for j in range(N):
    statement=statements[j]
    #print(statement)
    for x,y in statement:
      #print('honest&(1<<x) {} x {} y {}'.format(honest&(1<<x),x,y))
      if (honest&(1<<j))>>j ==1:
        #print('honest')
        flag*=((honest&(1<<x))>>x ==y)
      else:
        flag*=(honest&(1<<x)>>x !=y)

    #print(flag)
  if flag==True:
    honests.append(honest)

n_honests=[]
for honest in honests:
  n_honest=0
  for i in range(N):
    n_honest+=(honest&(1<<i))>>i
  n_honests.append(n_honest)

print(max(n_honests))

Submission status: Wrong Answer

Solution code:
n = int(input())

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
#print(person_list)
#print(syogen_list)

for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        #print(bin(bit))
        if break_flag:
            break
        if (bit >> i) & 1: #人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1): #正直としているのに証言が食い違えばbreak
                    break_flag = 1
                    #print("1_break",bit>>(person_list[i][j]-1))
                    break
                if j == len(syogen_list[i])-1:
                    bit_1_cnt += 1
#        else: #人iが嘘つき
#            for j in range(len(syogen_list[i])):
#                if syogen_list[i][j] == ((bit>>(person_list[i][j]-1))&1):
#                    break_flag = 1
#                    #print("0_break")
#                    break
        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
            #print(bin(bit), bit_1_cnt)
            #print("correct")
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
#print(person_list)
#print(syogen_list)

for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        #print(bin(bit))
        if break_flag:
            break
        if (bit >> i) & 1: #人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1):
                    break_flag = 1
                    #print("1_break",bit>>(person_list[i][j]-1))
                    break
                if j == len(syogen_list[i])-1:
                    bit_1_cnt += 1
        else: #人iが嘘つき
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] == ((bit>>(person_list[i][j]-1))&1):
                    break_flag = 1
                    #print("0_break")
                    break
        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
            #print(bin(bit), bit_1_cnt)
            #print("correct")
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a_list = []
person_list = []
syogen_list = []
ans = 0

for i in range(0, n):
    w = []
    v = []
    a = int(input())
    for j in range(0, a):
        x,y = map(int,input().split())
        w.append(x)
        v.append(y)
    person_list.append(w)
    syogen_list.append(v)
#print(person_list)
#print(syogen_list)

for bit in range(1 << n):
    break_flag = 0
    bit_1_cnt = 0
    for i in range(n):
        #print(bin(bit))
        if break_flag:
            break
        if (bit >> i) & 1: #人iが正直
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] != ((bit>>(person_list[i][j]-1))&1):
                    break_flag = 1
                    #print("1_break",bit>>(person_list[i][j]-1))
                    break
                bit_1_cnt += 1
        else: #人iが嘘つき
            for j in range(len(syogen_list[i])):
                if syogen_list[i][j] == ((bit>>(person_list[i][j]-1))&1):
                    break_flag = 1
                    #print("0_break")
                    break
        if break_flag==0 and i==n-1:
            ans = max(ans, bit_1_cnt)
            #print(bin(bit), bit_1_cnt)
            #print("correct")
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
speech_l=[[] for _ in range(N)]
for i in range(N):
    tmp=int(input())
    for j in range(tmp):
        speech_l[i].append(list(map(int,input().split())))
for i in range(2**N):
    sw=0
    l=[0]*N
    tmp=0
    for j in range(N):
        if ((i >> j)&1):#1なら正直者
            tmp+=1
            l[j]=1
    for j in range(N):
        if l[j] == 1:
            for k in speech_l[j]:
                if l[k[0]-1] != k[1]:
                    sw=1
        else:
            if l[j] == 0:
                for k in speech_l[j]:
                    if l[k[0]-1] == k[1]:
                        sw=1
    if sw==0:
        ans=max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
hatsugen = [[0] * (n+1) for i in range(n+1)]
memo = [[0] * (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())
        if y==0:
            hatsugen[i][x] = -1
            memo[x][i] = -1
        else:
            hatsugen[i][x] = y
            memo[x][i] = y
for i in range(1,n+1):
    print(hatsugen[i])
print('---')
for i in range(1,n+1):
    print(memo[i])

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
l = []
for i in range(n):
  d = int(input())
  for dd in range(d):
    x, y = map(int, input().split())
    l.append([i, x-1, y])
    
ans = 0
for p in itertools.product([0, 1], repeat=n):
  for ll in l:
    if p[ll[0]] == 1 and p[ll[1]] != ll[2]:
	    break
    else:
	    ans = max(ans, sum(p))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    xy = [list(map(int, input().split())) for _ in range(a)]
    A.append([a, xy])
# print(A)

# 下からi桁目のbitが1->人iは正直
# 下からi桁目のbitが0->人iは不親切

ans = 0
for i in range(2**N):
    for j in range(N):
        flag = 0
        for k in range(A[j][0]):
            l = A[j][1][k][0]
            if not (i >> l) & 1 == A[j][1][k][1]:
                flag = 1
                break
        if flag == 1:
            break
    else:
        # print(bin(i))
        ct = 0
        for l in range(N):
            ct += ((i >> l) & 1)
        ans = max(ans, ct)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def pos(self, x, y):
        return y * (self.w + 2) + x + 1

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

        ans = 0
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                pass # ここから何か書いてね
def bc(bi):
    # bit-count
    ret = 0
    while(bi > 0):
        if bi & 1 == 1:
            ret += 1
        bi //= 2
    return ret

def judge(bi, shogen, n):
    hito = []

    for i in range(n):
        hito.append(bi & 1)
        bi //= 2
    # print(hito)
    for i, sho in enumerate(shogen):
        for sh in sho:
            tgt, bo = sh
            tgt -= 1
            if hito[tgt] == hito[i] ^ bo:
                return -1

    return sum(hito)

def solve():
    n = getN()
    shogen = []
    for i in range(n):
        a = getN()
        tmp = []
        for j in range(a):
            tmp.append(getList())
        shogen.append(tmp)
    ans = 0
    # print(shogen)
    for bi in range(1 << n):
        ans = max(ans, judge(bi, shogen, n))
        # print(ans)

    print(ans)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()