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:
# -*- coding: utf-8 -*-
import numpy as np
import random

N = int(input())
R = np.full((N, N), 2, dtype=np.uint8)
S = np.full((N, N), 2, dtype=np.uint8)
A = []
for i in range(N):
  A.append(int(input()))
  for j in range(A[i]):
    x, y = map(int, input().split())
    R[i, x-1] = y

l = []
for i in range(N):
  l.append(str(i))

def contra(M, N, st):
  for i in range(N):
    if(st[i] == '1' and sum(M[:,i] == 0) != 0):
      return False;
    elif(st[i] == '0' and sum(M[:,i] == 1) != 0):
      return False;
  return True

def selected_set(l, i):
  tmp = []
  if(i == 0):
    return tmp
  elif(i == 1):
    return l
  elif(i == len(l)):
    tmp.append(''.join(l))
    return tmp
  else:
    for k in range(len(l)-i+1):
      st = l[k]
      ll = l[k+1:]
      tl = selected_set(ll, i-1)
      res = [st+p for p in tl]
      tmp += res
    return tmp

num = 0
for i in range(N):
  st = ['1']*N
  ll = selected_set(l, i)
  if(len(ll) == 0):
    if(contra(R, N, st)):
      num = N-i
      break;

  for zero_key in ll:
    st = ['1']*N
    S = np.full((N, N), 2, dtype=np.uint8)
    for p in range(i):
      st[int(zero_key[p])] = '0'
    for k in range(1, len(st)+1):
      if(st[-k] == '1'):
        S[N-k, :] = R[N-k,:]
    if(contra(S, N, st)):
      num = N-i
      break;
  else:
    continue
  break

print(num)

Submission status: Wrong Answer

Solution code:
# ABC147_C
N=int(input())
A=[]
FA=0

def count_bin(ar):
    ar=bin(ar)[2:]
    cnt=0
    for i in ar:
        cnt+=int(i)
    return cnt

for _ in range(N):
    num=int(input())
    B=[]
    for _ in range(num):
        B.append(list(map(int,input().split())))
    A.append(B)
#ansリストが1の証言を抽出して、その人の証言とansリストの整合性を照らし合わせる
ans=0
for _ in range(2**N):#正解の可能性がある組み合わせ
    fil=1
    end=0
    for i in range(N+1):#証言者の人数 i は証言者のindex
        if (ans&fil)==1:#ansのi番目のbitが1の場合==i番目の人を正直と仮定した場合
            for j in range(len(A[i])):#i番目の人の証言の数だけループ
                shogen=A[i][j]#i番目の人のj個目の証言
                x=1<<(shogen[0]-1)#x番目の人
                y=shogen[1]

                if y!=(ans&x):#i番目の人のj番目の証言のと、仮の正解を比較して、異なっていたらそれは正解ではない
                    end=1
        fil=fil<<1

    if (end==0)and(count_bin(ans)>count_bin(FA)):
        FA=ans
    ans+=1
print(count_bin(FA))

Submission status: Wrong Answer

Solution code:
# ABC147_C
N=int(input())
A=[]
FA=0

def count_bin(ar):
    ar=bin(ar)[2:]
    cnt=0
    for i in ar:
        cnt+=int(i)
    return cnt

for _ in range(N):
    num=int(input())
    B=[]
    for _ in range(num):
        B.append(list(map(int,input().split())))
    A.append(B)
#ansリストが1の証言を抽出して、その人の証言とansリストの整合性を照らし合わせる
ans=0
for _ in range(2**N):#正解の可能性がある組み合わせ
    fil=2**0
    end=0
    for i in range(N):#証言者の人数 i は証言者のindex
        if (ans&fil)==1:#ansのi番目のbitが1の場合==i番目の人を正直と仮定した場合
            for j in range(len(A[i])):#i番目の人の証言の数だけループ
                shogen=A[i][j]#i番目の人のj個目の証言
                x=1<<(shogen[0]-1)#x番目の人
                y=shogen[1]

                if y!=(ans&x):#i番目の人のj番目の証言のと、仮の正解を比較して、異なっていたらそれは正解ではない
                    end=1
        fil=fil<<1

    if (end==0)and(count_bin(ans)>count_bin(FA)):
        FA=ans
    ans+=1
print(count_bin(FA))

Submission status: Wrong Answer

Solution code:
# ABC147_C
N=int(input())
A=[]
FA=0

def count_bin(ar):
    ar=bin(ar)[2:]
    cnt=0
    for i in ar:
        cnt+=int(i)
    return cnt

for _ in range(N):
    num=int(input())
    B=[]
    for _ in range(num):
        B.append(list(map(int,input().split())))
    A.append(B)
#ansリストが1の証言を抽出して、その人の証言とansリストの整合性を照らし合わせる
ans=0
for _ in range (2**N):#正解の可能性がある組み合わせ
    fil=2**0
    end=0
    for i in range(N):#証言者の人数 i は証言者のindex
        if end==1:
            break

        if (ans&fil)==1:#ansのi番目のbitが1の場合==i番目の人を正直と仮定した場合
            for j in range(len(A[i])):#i番目の人の証言の数だけループ
                shogen=A[i][j]#i番目の人のj個目の証言
                x=1<<(shogen[0]-1)#x番目の人
                y=shogen[1]

                if y!=(ans&x):#i番目の人のj番目の証言のと、仮の正解を比較して、異なっていたらそれは正解ではない
                    end=1
                    break
        fil=fil<<1

    if (end==0)and(count_bin(ans)>count_bin(FA)):
        FA=ans
    ans+=1           
print(count_bin(FA))

Submission status: Wrong Answer

Solution code:
N = int(input())
x = []
a = 0
for i in range(N):
  y = int(input())
  x.append([input() for j in range(y)])

Submission status: Wrong Answer

Solution code:
N=int(input())
lst = [[None for _ in range(N)] for _ in range(N)]
for idx in range(N):
    num = int(input())
    for idy in range(num):
        x,y=map(int ,input().split())
        lst[idx][x-1] = y
lst2=[None for _ in range(N)] 
for idx in range(N):
    honestFlg = 1
    for idy in range(N):
        if (idx == idy):
            continue
        if (lst[idx][idy] == 1 and lst[idy][idx] == 0):
            honestFlg = 0
        if (lst[idx][idy] == 1 and lst2[idy] == 0):
            honestFlg = 0
    if (lst2[idx] != 0):
        lst2[idx] = honestFlg
    if (lst2[idx] == 1):
        for idy in range(N):
            if (lst[idx][idy] == 0):
                lst2[idy] = 0
    else:
        for idy in range(N):
            if (lst[idy][idx] == 1):
                lst2[idy] = 0
        
print(sum(lst2))

Submission status: Wrong Answer

Solution code:
N=int(input())
lst = [[None for _ in range(N)] for _ in range(N)]
for idx in range(N):
    num = int(input())
    for idy in range(num):
        x,y=map(int ,input().split())
        lst[idx][x-1] = y
lst2=[None for _ in range(N)] 
for idx in range(N):
    honestFlg = 1
    for idy in range(N):
        if (lst[idx][idy] == 1 and lst[idy][idx] == 0):
            honestFlg = 0
    if (lst2[idx] != 0):
        lst2[idx] = honestFlg
    if (lst2[idx] == 1):
        for idy in range(N):
            if (lst[idx][idy] == 0):
                lst2[idy] = 0
    else:
        for idy in range(N):
            if (lst[idy][idx] == 1):
                lst2[idy] = 0
print(sum(lst2))

Submission status: Wrong Answer

Solution code:
N=int(input())
lst = [[None for _ in range(N)] for _ in range(N)]
for idx in range(N):
    num = int(input())
    for idy in range(num):
        x,y=map(int ,input().split())
        lst[idx][x-1] = y

lst2=[None for _ in range(N)] 
for idx in range(N):
    if (lst2[idx] == 0):
        continue
    honestFlg = 1
    for idy in range(N):
        if (lst[idx][idy] == 1 and lst[idy][idx] == 0):
            honestFlg = 0
    lst2[idx] = honestFlg
    if (honestFlg == 1):
        for idy in range(N):
            if (lst[idx][idy] == 0):
                lst2[idy] = 0
print(sum(lst2))

Submission status: Wrong Answer

Solution code:
p_num = int(input())

list = [1 for i in range(p_num)]

for i in range(p_num):
  c_num = int(input())
  for j in range(c_num):
    p, com = [int(i) for i in input().split(" ")]
    if(com == 0):
      list[p-1] = 0
  
count = 0
for i in range(len(list)):
  if(list[i] == 1):
    count += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
XYs = []
for i in range(N):
    a = int(input())
    for j in range(a):
        x, y = tuple(map(int, input().split()))
        XYs.append((i + 1, x, y))

sw = [1] * (N + 1)
f = False
for i in range(0, N + 1):
    sw[i] = 0
    for j in range(i, N + 1):
        sw[j] = 0
        for (k, x, y) in XYs:
            if sw[k] == 0:
                continue
            if sw[x] != y:
                break
        else:
            print(sum(sw))
            f = True
        if f:
            break
        sw[j] = 1
        sw[i] = 0
    if f:
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
XYs = []
for i in range(N):
    a = int(input())
    for j in range(a):
        x, y = tuple(map(int, input().split()))
        XYs.append((i + 1, x, y))

sw = [1] * (N + 1)
f = False
for i in range(0, N + 1):
    sw[i] = 0
    for j in range(i, N + 1):
        sw[j] = 0
        for (k, x, y) in XYs:
            if sw[k] == 0:
                continue
            if sw[x] != y:
                break
        else:
            print(sum(sw))
            f = True
        if f:
            break
        sw[j] = 1
        sw[0] = 0
    if f:
        break

Submission status: Wrong Answer

Solution code:
import sys

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
# sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def grid(n): return [s_list() for _ in range(n)]

def main():
    n = si()
    ixy = [[] for _ in range(n)]
    for i in range(n):
        for a in range(int(input())):
            ixy[i].append([int(m) - 1 for m in input().split()])

    # 真：0，不親切：-1
    nums = [i for i in range(n)]
    queue = deque()
    hash = defaultdict(lambda: -2)

    flag = 0  # 全体の枠組みを抜けるためのflag
    ans = 0
    while ans < n and flag == 0:
        for balls in combinations(nums, ans + 1):
            balls = list(balls)  # 合計人数を調べるために使用
            for h in balls:
                hash[h] = 0
                queue.append(h)
            sign = queue.popleft()

            brefl = 0  # そのballsでの探索を抜けるためのflag
            while brefl == 0:
                for x, y in ixy[sign]:
                    if y == -1:  # 不親切
                        if x in hash and hash[x] == 0:  # 0-> -1 ×
                            flag = 1
                            brefl = 1
                            break  # 矛盾
                        else:  # -2-> -1 ○
                            hash[x] = -1
                    else:  # 真
                        if x not in hash:  # -2-> 0 ○
                            hash[x] = 0
                            queue.append(x)
                            balls.append(x)
                        elif x in hash and hash[x] == -1:  # -1-> 0 ×
                            flag = 1
                            brefl = 1
                            break  # 矛盾

                if queue == deque():
                    break  # 探索終了
                else:
                    sign = queue.popleft()


            if len(balls) > ans and brefl == 0:
                ans = len(balls)
                flag = 0
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
# sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def grid(n): return [s_list() for _ in range(n)]

def main():
    n = si()
    ixy = [[] for _ in range(n)]
    for i in range(n):
        for a in range(int(input())):
            ixy[i].append([int(m) - 1 for m in input().split()])

    # 真：0，うそ：-1
    nums = [i for i in range(n)]
    queue = deque()
    hash = defaultdict(int)

    flag = 0  # 全体の枠組みを抜けるためのflag
    ans = 0
    while ans < n and flag == 0:
        for balls in itertools.combinations(nums, ans + 1):
            balls = list(balls)  # 合計人数を調べるために使用
            for h in balls:
                hash[h] = 1
                queue.append(h)
            sign = queue.popleft()

            brefl = 0  # そのballsでの探索を抜けるためのflag
            while brefl == 0:
                for x, y in ixy[sign]:
                    if y == -1:
                        if x in hash:
                            flag = 1
                            brefl = 1
                            break  # 矛盾
                    else:
                        if x not in hash:
                            hash[x] = 1
                            queue.append(x)
                            balls.append(x)
                if queue == deque():
                    break  # 探索終了
                else:
                    sign = queue.popleft()


            if len(balls) > ans and brefl == 0:
                ans = len(balls)
                flag = 0
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
# sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def grid(n): return [s_list() for _ in range(n)]

def main():
    n = si()
    ixy = [[] for _ in range(n)]
    for i in range(n):
        for a in range(int(input())):
            ixy[i].append([int(m) - 1 for m in input().split()])

    # 真：0，うそ：-1
    nums = [i for i in range(n)]
    queue = deque()
    hash = defaultdict(int)

    flag = 0  # 全体の枠組みを抜けるためのflag
    ans = 0
    while ans < n and flag == 0:
        for balls in itertools.combinations(nums, ans + 1):
            for h in balls:
                hash[h] = 1
                queue.append(h)
            sign = queue.popleft()

            brefl = 0  # そのballsでの探索を抜けるためのflag
            while brefl == 0:
                for x, y in ixy[sign]:
                    if y == -1:
                        if x in hash:
                            flag = 1
                            brefl = 1
                            break  # 矛盾
                    else:
                        if x not in hash:
                            hash[x] = 1
                            queue.append(x)
                if queue == deque():
                    break  # 矛盾
                else:
                    sign = queue.popleft()


            if len(balls) > ans and brefl == 0:
                ans = len(balls)
                flag = 0
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
# from itertools import permutations, combinations, product, accumulate, groupby
# from bisect import bisect_left, bisect_right, insort_left, insort_right
# from operator import itemgetter as ig
# sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []; mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def grid(n): return [s_list() for _ in range(n)]

def main():
    n = si()
    ixy = [[] for _ in range(n)]
    for i in range(n):
        for a in range(int(input())):
            ixy[i].append([int(m) - 1 for m in input().split()])

    # 真：0，うそ：-1
    nums = [i for i in range(n)]
    queue = deque()
    hash = defaultdict(int)

    flag = 0
    ans = 0
    brefl = 0
    while ans < n and flag == 0:
        for balls in itertools.combinations(nums, ans + 1):
            for h in balls:
                hash[h] = 1
                queue.append(h)
            sign = queue.popleft()

            while brefl == 0:
                for x, y in ixy[sign]:
                    if y == -1:
                        if x in hash:
                            flag = 1
                            brefl = 1
                            break  # 矛盾
                    else:
                        if x not in hash:
                            hash[x] = 1
                            queue.append(x)
                if queue == deque():
                    break  # 矛盾
                else:
                    sign = queue.popleft()


            if len(balls) > ans and brefl == 0:
                ans = len(balls)
                flag = 0
                break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def judge(ans,syojiki,usotuki):
    if (~ans & syojiki)==0 and (ans & usotuki)==0:
        return 1
    else:
        return 0

n = int(input())
syojiki = [0 for i in range(n)]
usotuki = [0 for i in range(n)]
ans_count = []
flag = 0
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        if y == 1:
            syojiki[i] = syojiki[i] | x
        else:
            usotuki[i] = usotuki[i] | x

for v in range(2**n):
    for i in range(n):
        if (v>>i)&1:
            flag = judge(v,syojiki[i],usotuki[i])
            if flag == 0:
                break
    if flag == 1:
        ans_count.append(v)
max_count = 0
if len(ans_count) >= 1:
    for i in ans_count:
        one_count = bin(i).count('1')
        if max_count<one_count:
            max_count = one_count
    print(max_count)
else:
    print(0)

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]):
        x,y = map(int,input().split())
        xy[i].append([x-1,y])
print(xy)
ans = 0
for i in range(1<<(n)):
    memo = []
    cnt = 0
    for j in range(n):
        if ((i>>j)&1):
            memo.append(1)
            cnt += 1
        else:
            memo.append(0)
    
    cntn = True     
    for j in range(n):
        if memo[j] == 0:
            continue
        for k in range(a[j]):
           prs = xy[j][k][0]

           if memo[prs] != xy[j][k][1]:
               cntn = False
    if not(cntn):
        continue
    ans = max(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
# print(A)

ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                if l[i] != A[i+1][j][1]:
                    flag = False
    if flag:
        ans = max(ans, sum(l))
    # if len(l) <= 2:
    #     ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    l = []
    for j in range(a):
        tmp = list(map(int, input().split()))
        l.append(tmp[:])
    A[i+1] = l[:]
# print(A)

ans = -1
for bit in range(2**N):
    l = []
    # 正直者と嘘つきの配列
    for i in range(N):
        if (bit >> i) & 1 == 1:
            l.append(1)
        else:
            l.append(0)
    
    flag = True
    for i in range(N):
        if (bit >> i) & 1 == 1:
            for j in range(len(A[i+1])):
                if l[i] != A[i+1][j][1]:
                    flag = False
    if flag:
        ans = max(ans, sum(l))
    if len(l) <= 2:
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A_map = {}

# input
for i in range(N):
    A = int(input())
    if A > 0:
        for j in range(A):
            xy = list(map(int,input().split()))
            if i in A_map.keys():
                A_map[i].append(xy)
            else:
                A_map[i] = [xy]
ans = 0

for bits in range(1,2**N):
    honest = True
    for i in range(1,N+1):
        if not (bits & (1 << (i-1))): continue

        if i in A_map.keys():
            for a in A_map[i]:   
                if ((bits >> (a[0] -  1)) & 1) ^ a[1] : honest = False
    if honest : 
        ans = max(ans, bin(bits).count('1'))

print(ans)

Submission status: Wrong Answer

Solution code:
#パクリです
n = int(input())
xy=[[] for i in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        xy[i].append((x-1, y))
cnt=0
for i in range(1,2**n):
  s=True
  for j in range(n):
    if (i >> j) & 1 ==0:
      continue
    if s==False:
      break
      for x,y in xy[j]:
        if (i >> x)&1 !=y:
          s=False
          break
  if s==True:
    cnt=max(cnt,bin(i)[2:].count('1'))
print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
a_list=[]
x_list=[]
y_list=[]
for i in range(n):
  a=int(input())
  a_list.append(a)
  X=[]
  Y=[]
  for j in range(a):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
  x_list.append(X)
  y_list.append(Y)
  
cnt=0
for i in range(n):
  a=list(combinations(range(n),n-i))
  for j in range(len(a)):
    b=set()
    c=set()
    for k in a[j]:
      for l in range(a_list[k]):
        if y_list[k][l]==0:
          b.add(x_list[k][l])
        elif y_list[k][l]==1:
          c.add(x_list[k][l])
    if len(b&c)==0:
      cnt=max(cnt,n-i)
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())
saids = {}  # saids[i][j] は，人iの，人jについての証言(True:正直 False:不親切)
for i in range(n):
    said = {}
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        said[x] = y == 1
    saids[i] = said
ans = 0
for p in range(2**n):
    honest = [i for i in range(n) if p & 2 ** i != 0]
    for x, y in itertools.product(honest, range(n)):
        if y not in saids[x]:
            continue
        if saids[x][y] is False and y in honest:
            break
        if saids[x][y] is True and y not in honest:
            break
    else:
        ans = max(ans, len(honest))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
say = []
for i in range(N):
    A = int(input())
    t = []
    for j in range(A):
        s = list(map(int,input().split()))
        t.append(s)
    say.append(t)

a = 0
for i in range(2**N):
    judge = 1
    c = 0
    
    for j in range(N):
        if judge == 0:
            break
        if ((i >> j) & 1):
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) != say[j][k][1]:
                    judge = 0
        else:
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) == say[j][k][1]:
                    judge = 0
    
    if judge:
        c = bin(i).count("1")
        a = max(a,c)
print(a)

Submission status: Wrong Answer

Solution code:
def hou2(tarrs, s, N):
    def checkTestimony(s, t):
        scopy = s[:]
        for i in range(len(s)):
            if s[i] != t[i] and s[i] != 0 and t[i] != 0:
                return None
            if t[i]:
                scopy[i] = t[i]
        return scopy
 
    def search(pos, N, s, acc):
        if pos < N:
            check_tp = checkTestimony(s, tarrs[pos])
            if s[pos] == 1:
                s[pos] = -1
                if check_tp:
                    check_tp[pos] = 1
                    return search(pos + 1, N, check_tp, acc + 1)
                else:
                    return 0
            if check_tp and s[pos] == 0:
                s[pos] = -1
                check_tp[pos] = 1
                return max(search(pos + 1, N, check_tp, acc + 1), search(pos + 1, N, s, acc))
            else: # testimony unacceptable, assuming unkind
                s[pos] = -1
                return search(pos + 1, N, s, acc)
        else:
            print("fin ", acc)
            return acc
 
    return search(0, N, s, 0)
    
 
if __name__ == "__main__":
    import sys
    in_arr = []
    for line in sys.stdin:
        in_arr.append([int(_) for _ in line.strip().split()])
    N = in_arr[0][0]
    i = 1
    tarrs = []
    s = [0] * N
    while i < len(in_arr):
        tnum = in_arr[i][0]
        tarr = [0] * N
        for j in range(tnum):
            x, y = in_arr[1 + j + i]
            tarr[x - 1] = 1 if y else -1 # -1 claimed unkind, 1 claimed honest
        if tarr[len(tarrs)] == -1: # claimed self to be unkind
            s[len(tarrs)] = -1
        tarrs.append(tarr)
        i += tnum + 1

Submission status: Wrong Answer

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

ans = 0
for i in range(1,2**n):
	cur_bit = bin(i)[2:].zfill(len(bin(2**n-1)[2:]))
	# print(cur_bit)
	res = list(map(int,cur_bit))
	flag = 1
	j = 0
	for c,xy in zip(cur_bit,XY):
		res[j] = int(c)
		for x,y in xy:
			if c == "1":
				if res[x] != y:
					flag = 0
					break
				# elif res[j] == 1:
				# 	flag = 0
				# 	break
				res[x] = y
			elif c == "0":
				if res[x] == y:
					flag = 0
					break
				# elif res[j] == 0:
				# 	flag = 0
				# 	break
				res[x] = abs(y-1)
		# print(res)
		j += 1
	if flag:
		try:
			ans = max(ans,res.count(1))
			# print("ans->",ans)
		except ValueError:
			pass

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=[]

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

for i in range(2**n):
      L=[0]*n
      for j in range(n):
            if ((i>>j)&1):
                  L[j]=1
      cc=0
      if 1 in L:
            flag=1
            for k in range(n):
                  if L[k]==1:
                        for m in range(a[k]):
                              if L[b[k][m][0]-1]!=b[k][m][1]:
                                    flag=0
                                    break
            if flag==1:
                  cc=max(sum(L),cc)
print(cc)

Submission status: Wrong Answer

Solution code:
N = int(input())
say = []
for i in range(N):
    A = int(input())
    t = []
    for j in range(A):
        s = list(map(int,input().split()))
        t.append(s)
    say.append(t)

a = 0
for i in range(2**N):
    judge = 1
    c = 0
    
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) != say[j][k][1]:
                    judge = 0
        else:
            for k in range(len(say[j])):
                if ((i>>(say[j][k][0]-1))&1) == say[j][k][1]:
                    judge = 0
    
    if judge:
        c = bin(i).count("1")
        a = max(a,c)
print(a)