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:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
a=[]
x=[]
y=[]

for i in range(n):
    a0=ii()
    a.append(a0)
    xtemp=[]
    ytemp=[]
    for j in range(a0):
        x0,y0=mii()
        x0-=1
        xtemp.append(x0)
        ytemp.append(y0)
    x.append(xtemp)
    y.append(ytemp)

ans=0
for i in product([0,1], repeat=n):
    arr=list(deepcopy(i))


    #嘘つきは0 正直だと1 0だと反転 1だとそのまま

    for j in range(n):
        temp=0
        if i[j]==1:
            for k in range(a[j]):
                if i[x[j][k]]!=y[j][k]:
                    arr[x[j][k]]=0
                    if i[x[j][k]]==1:
                        arr[j]=0


    ans=max(ans,sum(arr))
    #ans=max(cnt,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
a=[]
x=[]
y=[]

for i in range(n):
    a0=ii()
    a.append(a0)
    xtemp=[]
    ytemp=[]
    for j in range(a0):
        x0,y0=mii()
        x0-=1
        xtemp.append(x0)
        ytemp.append(y0)
    x.append(xtemp)
    y.append(ytemp)

ans=0
for i in product([0,1], repeat=n):
    arr=list(deepcopy(i))


    #嘘つきは0 正直だと1 0だと反転 1だとそのまま

    for j in range(n):
        temp=0
        if i[j]==1:
            for k in range(a[j]):
                if i[x[j][k]]!=y[j][k]:
                    arr[x[j][k]]=0
                    arr[j]=0


    ans=max(ans,sum(arr))
    #ans=max(cnt,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3


def put(a, k, v):
    if k in a:
        if a[k] != v:
            return False
    else:
        a[k] = v
    return True


def check(n, t, i):
    a = {}
    m = 0
    for j in range(n):
        honest = i >> j & 1
        m += honest
        if not put(a, j+1, honest):
            return 0
        for (k, h) in t[j+1].items():
            if not put(a, k, h if honest else 1 - h):
                return 0
    return m


def solve(n, t):
    print(max([check(n, t, i) for i in range(1 << n)]))


def main():
    t = {}
    n = int(input())
    for i in range(n):
        a = int(input())
        t[i+1] = {}
        for j in (range(a)):
            x, y = map(int, input().split())
            t[i+1][x] = y
    solve(n, t)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
a=[]
x=[]
y=[]

for i in range(n):
    a0=ii()
    a.append(a0)
    xtemp=[]
    ytemp=[]
    for j in range(a0):
        x0,y0=mii()
        x0-=1
        xtemp.append(x0)
        ytemp.append(y0)
    x.append(xtemp)
    y.append(ytemp)

ans=0
for i in product([0,1], repeat=n):

    #嘘つきは0 正直だと1 0だと反転 1だとそのまま
    cnt=0
    for j in range(n):
        temp=0
        if i[j]==1:
            for k in range(a[j]):

                if i[x[j][k]]==y[j][k]:
                    temp+=1

        if temp==a[j]:
            cnt+=1
    ans=max(cnt,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
input = sys.stdin.buffer.readline
def inputS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

N  = int(input())
XY = [[] for _ in range(N)] # 証言者

for i in range(N):
  A = int(input())
  for i in range(A):
    ind, bl = map(int, input().split())
    XY[i].append((ind-1, bl))
    
ans = 0
for bit in range(1<<N):
  cnt = 0
  ok = True
  for i in range(N):
    # i 人目が「不親切」だったら、証言はすべて無意味
    if not bit >> i & 1:
      continue
    # 証言通りかそれぞれ確認
    for x, y in XY[i]:
      # y = 1 なのに「不親切」だったらダメ
      if (y == 1 and ~(bit & (1 << x))):
        ok = False
        break
        
      # y = 0 なのに「正直者」だったらダメ
      if (y == 0 and (bit & (1 << x))):
        ok = False
        break
    if ok:
      cnt += 1
    else:
      break
  else:
    ans = max(ans, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import itertools
import numpy as np

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

# 何人目かを正直者か優しくない人かを判断するためのnp.array
A = np.array(list(itertools.product([0, 1], repeat=N)), np.bool)

for i, x, y in Info:
    bl = (~A[:, i]) | (A[:, x] == bool(y))
    A = A[bl]

print(A)

Submission status: Wrong Answer

Solution code:
N = int(input())

maxcnt = 0
ixy = []

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

# print(ixy)

# bit全探索


for bit in range((1 << N)):
    # 2重ループがうまく抜けられない...
    break_flag = False
    for i, x, y in ixy:
        # 対応するbitが1のとき正直者、0のとき嘘つき
        # 正直者iが
        if ((bit >> i) & 1):
            # xを正直者であると証言をしたとき
            if y & 1:
                # xに対応するbitが0ならば矛盾
                if ((bit >> x) == 0):
                    break_flag = True
                    # print("break1", i, x, y)
                    break
            # xを嘘つきであると証言したとき
            else:
                # xに対応するbitが1 (and) ならば矛盾
                if ((bit >> x) & 1):
                    break_flag = True
                    # print("break2", i, x, y)
                    break
        # 嘘つきiが
        else:
            # xを正直者であると証言をしたとき
            # xは嘘つきということになり
            if y & 1:
                # xに対応するbitが1 (and) ならば矛盾
                if ((bit >> x) & 1):
                    break_flag = True
                    # print("break3", i, x, y)
                    break
            # xを嘘つきであると証言したとき
            # xは正直者ということになり
            else:
                # xに対応するbitが0ならば矛盾
                if ((bit >> x) == 0):
                    break_flag = True
                    # print("break4", i, x, y)
                    break
    # breakしてきたときはカウントしない
    if break_flag:
        continue
    # ここまで全て矛盾がなければ立っているbitの数 (= 正直者の数) をカウント
    # 最大値を更新
    else:
        # print(bin(bit))
        maxcnt = max(maxcnt, bin(bit).count("1"))

print(maxcnt)

Submission status: Wrong Answer

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

def judge(X,Tes):
    for t in Tes:
        a = t[0]-1
        b = t[1]
        if X[a] == 2:
            X[a] = b
            if b == 1:
                judge(X,L[a])
        elif X[a] != b:
            return False

cnt = 0

for i in range(n):
    X=[2]*n
    X[i] = 1
    if judge(X,L[i]) != False:
        cnt = max(cnt,X.count(1))
        for j in range(n):
            if X[j] == 2:
                X1 = X.copy()
                X1[j] = 1
                if judge(X1,L[j]) != False:
                    X = X1
                    cnt = max(cnt,X.count(1))

print(cnt)

Submission status: Wrong Answer

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

def judge(X,Tes):
    for t in Tes:
        a = t[0]-1
        b = t[1]
        if X[a] == 2:
            X[a] = b
            if b == 1:
                judge(X,L[a])
        elif X[a] != b:
            return False

cnt = 0

for i in range(n):
    X=[2]*n
    X[i] = 1
    if judge(X,L[i]) != False:
        cnt = max(cnt,X.count(1))

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for i in range(n):
    num = int(input())
    for j in range(num):
        hi, tf = map(int,input().split())
        a.append([i,hi,tf])
print(a)

max = 0
for i in range(1,2**n):
    se = format(i,'b').zfill(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
list_A = [0 for i in range(0,N)]
list_xy = [0 for i in range(0,N)]
for i in range(0,N) :
    list_A[i] = int(input())
    list_xy[i] = [0 for i in range(0,list_A[i])]
    for j in range(0,list_A[i]) :
        x, y = map(int, input().split())
        list_xy[i][j] = (x, y)

# 0 False, 1 True

ans = 0

for t in range(0,2**N) :
    pat = list(reversed(format(t, "015b")))
    ok = True
    for i in range(0,N) :
        for j in range(0,list_A[i]) :
            man = list_xy[i][j][0] - 1
            if pat[i] == "1" :
                if pat[man] != str(list_xy[i][j][1]) :
                    ok = False
                    break
            if pat[i] == "0" :
                if pat[man] == str(list_xy[i][j][1]) :
                    ok = False
                    break
        else :
            continue
        break

    if ok == True :
        ans_pat = pat.count("1")
        ans = max(ans, ans_pat)

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
for i in range(0,N):
    a=int(input())
    b=[]
    for j in range(0,a):
        b.append(list(map(int,input().split())))
    for B in b:
        B[0]-=1
    A.append(b)
import itertools
ans=0
for i in itertools.product([-1,1],repeat=N):
    OK=True
    for j in range(0,N):
        if i[j]==-1:
            for a in A[j]:
                if a[1]==0:
                    if i[a[0]]==-1:
                        OK=False
                else:
                    if i[a[0]]==1:
                        OK=False
        else:
            for a in A[j]:
                if a[1]==0:
                    if i[a[0]]==1:
                        OK=False
                else:
                    if i[a[0]]==-1:
                        OK=False
        if not OK:
            break
    if i.count(1)>ans and OK:
        ans=i.count(1)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
for i in range(0,N):
    a=int(input())
    b=[]
    for j in range(0,a):
        b.append(list(map(int,input().split())))
    for B in b:
        B[0]-=1
    A.append(b)
import itertools
ans=0
for i in itertools.product([0,1],repeat=N):
    temp=1
    S=[-1 for j in range(0,N)]
    for j in range(0,N):
        if i[j]==0:
            for a in A[j]:
                if a[1]==0:
                    if i[a[0]]==0:
                        temp=0
                else:
                    if i[a[0]]==1:
                        temp=0
        else:
            for a in A[j]:
                if a[1]==0:
                    if i[a[0]]==1:
                        temp=0
                else:
                    if i[a[0]]==0:
                        temp=0
    if sum(i)>ans and temp==1:
        ans=sum(i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [-1 for i in range(N+1)]
x = [[-1 for _ in range(N+1)]for _ in range(N+1)]
y = [[-1 for _ in range(N+1)]for _ in range(N+1)]
for i in range(1,N+1):
	A[i] = int(input())
	for j in range(1,A[i]+1):
		x[i][j],y[i][j] = map(int,input().split())



ans = 0
correct = []
l = -1
"""

"""
for i in range(1,N+1):
	for j in range(i+1,N+1):
		for k in range(1,A[i]+1):
			if x[i][k] == j and i == x[j][k]:
				if y[i][k] ==1 and y[j][k] == 1:
					ans += 2
					correct.append(i)
					correct.append(j)

for i in range(len(correct)):	
	for k in range(1,A[correct[i]]+1):
		if y[correct[i]][k] == 1:
			correct.append(x[correct[i]][k])

print(len(list(set(correct))))

Submission status: Wrong Answer

Solution code:
"""n=int(input())
c=[[0] * n for i in range(n)]
for i in range(n):
    a=int(input())
    e=[[int(i) for i in input().split()] for i in range(a)] 
    for j in range(b):
        c[i][e[j][0]-1]=e[j][1]
print(c)
"""
import copy
n=int(input())
xy=[[] for i in range(n)]

for i in range(n):
    a=int(input())
    for j in range(a):
        xy[i].append(list(map(int, input().split())))
xyc=copy.deepcopy(xy)

print(xy)
for i in range(2**n):
    bit=[0]*n
    for j in range(n):
        if ((i >> j) & 1):
            bit[j]=1
    print(bit)#0が嘘つき1が正直
    for j in range(n):
        for z in range(len(xy[j])):
            if bit[j]==0:
                if xy[j][z][1]==1:
                    xy[j][z][1]=0
                else:
                    xy[j][z][1]=1
    
    print(xy)
    print(xyc)
    xy=copy.deepcopy(xyc)

print(xy)

Submission status: Wrong Answer

Solution code:
n=int(input())
dic={i:{j:2 for j in range(n+1)}for i in range(n+1)}
proof={k:0 for k in range(n+1)}
       
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        dic[i+1][x]=y
        proof[i+1]=x
                    
#dicに誰々が正直者か嘘つきであるかということをまとめるdic[x][y]=? xからｙは正直者あるいは真偽不明の者である

maxi=0

for _ in range(1,2**n): 
    #計算量 3* (10)**4
    choice=format(_,"0%ib"%n)
    #1が正直者,0がよくわからない人
    #正直者の発言が全て一致していなくてはいけない　それであれば、矛盾は生じない
    flag=True
    honest=[]
    for i in range(n):
        if choice[i]=="1":
            honest.append(i+1)
        
    for j in range(n):
        P=proof[j+1]
        for some in honest:
            if dic[some][j+1]!=dic[P][j+1] and dic[some][j+1]<2:
                flag=False
                break
    if flag:
    	for some in honest:
      		for somes in honest:
        		if some!=somes and dic[some][somes]==0:
          			flag=False
          			break
                    
    if flag:
        maxi=max(maxi,len(honest))
print(maxi)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0 for i in range(n)]
for i in range(n):
  ka=int(input())
  r,w=[],[]
  for k in range(ka):
    x,y=map(int,input().split())
    r.append(x-1) if y else w.append(x-1)
  l[i]=(set(r),set(w))
ans=0
for j in range(2**n):
  v=format(j,"b").zfill(n)
  R,W=set(),set()
  RR={i for i in range(n) if v[i]=="1"}
  for h in RR:
    r,w=l[h]
    R|=r
    W|=w
  WW=set(range(n))-RR
  if len(RR&W) or len(WW&R) or len(R&W) :break
  else:ans=max(ans,len(RR))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
x = [[] for _ in range(n)]

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

# print(x)
ans = 0
for i in range(1<<n):
    
    cnt = bin(i).count("1")
    if ans > cnt:
        continue
    flag = True
    for j in range(n):
        # if i==3:
        #     print(i,j,i>>j&1,cnt)
        if i>>j & 1:
            # True if 1
            # if i==3:
                # print(i,j)
            for t in x[j]:
                # 証言:testimony
                # if i == 3:
                    # print(i,t[0]-1, i>>t[0]-1, t[1])
                if (i>>(t[0]-1) &1 ) != t[1]:
                    flag = False
                    break
    if flag == False:
        break
    if flag == True:
        # print(i) # 0 000
        ans = cnt

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
say = []
for i in range(n):
  a = int(input())
  s = []
  for j in range(a):
    x,y = map(int,input().split())
    s.append([x,y])
  say.append(s)
  
def check(say,tf):
  for s in say:
    for s_ in s:
      if tf[s_[0]-1] != s_[1]:
        return 0
  return 1

import copy
def make_say(say,tf):
  csay = copy.deepcopy(say)
  for i in range(len(csay)):
    if tf[i] == 0:
      for s in csay[i]:
        s[1] = (s[1]+1)%2
  return csay

m = 0
for i in range(2**n):
  tf = list(map(int,format(i, '0{}b'.format(n))))
  s = make_say(say,tf)
  if check(s,tf) == 1:
    if sum(tf) > m:
      m = sum(tf)
  else:
    continue
print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = []
remark = []
temp1 = []
b = []

for i in range(n):
    a = int(input())
    num.append(a)
    
    for j in range(a):
        b = list(map(int, input().split()))
        temp1.append(b)
    
    remark.append(temp1)
    temp1 = []
    
    ans = 0
for i in range(2 ** n):
    print(bin(i))
    temp2 = 0 #iの並びが可能か判定
    temp4 = 0 #1の数をカウント
    for j in range(n):
        if (i >> (n - 1 - j)) & 1 == 1:
            temp3 = 0
            temp4 += 1
            for k in range(num[j]):
                x = remark[j][k][0]
                y = remark[j][k][1]
                if (i >> n - x) & 1 == y:
                    temp3 += 1
                else:
                    break
            if temp3 == num[j]:
                temp2 += 1
        else:
            temp2 += 1
    if temp2 == n:
        ans = max(ans, temp4)
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    xy.append([])
    for j in range(a):
        tmp = list(map(int, input().split()))
        xy[i].append(tmp)
# bit全探索
# 範囲
ans = 0
s = 0
for i in range(2 ** n):
    # 判断用のリストを準備
    judge = []
    # 探索
    for j in range(n):
        if (i >> j) & 1:
            judge.append(1)
        else:
            judge.append(0)

    count = 0
    tmp_j = True
    for l in range(n):
        if tmp_j == False:
            break
        if judge[l] == 1:
            for a in range(len(xy[l])):
                if judge[xy[l][a][0] - 1] == xy[l][a][1]:
                    count = 1
                if judge[xy[l][a][0] - 1] != xy[l][a][1]:
                    count = 0
                    tmp_j = False
                    break
    if count == 1:
        s = sum(judge)
    if ans <= s:
        ans = s
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
for i in range(n):
    a = int(input())
    xy.append([])
    for j in range(a):
        tmp = list(map(int, input().split()))
        xy[i].append(tmp)
# bit全探索
# 範囲
ans = 0
for i in range(2 ** n):
    # 判断用のリストを準備
    judge = []
    # 探索
    for j in range(n):
        if (i >> j) & 1:
            judge.append(1)
        else:
            judge.append(0)

#    print(judge)
    count = 0
    tmp_j = True
    for l in range(n):
        if tmp_j == False:
            break
        if judge[l] == 1:
            for a in range(len(xy[l])):
                if judge[xy[l][a][0] - 1] == xy[l][a][1]:
                    count += 1
                if judge[xy[l][a][0] - 1] != xy[l][a][1]:
                    count = 0
                    tmp_j = False
                    break
    if ans <= count:
        ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(1,2**n):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      if H[j]==0:
        f=1
        break
      H[j]=1
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      if H[j]==1:
        f=1
        break
      H[j]=0
  if not f:
    print(i,j,H)
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(1,2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      if H[j]==0:
        f=1
        break
      H[j]=1
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      if H[j]==1:
        f=1
        break
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      if H[j]==0:
        f=1
        break
      H[j]=1
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      if H[j]==0:
        f=1
        break
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      H[j]=1
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    print(i,j)
    if i>>j&1:
      for l in L[j]:
        H[j]=1
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[[list(map(int,input().split())) for _ in range(int(input()))] for _ in range(n)]
h=0
for i in range(2**(n-1)):
  H=[2 for _ in range(n)]
  f=0
  for j in range(n):
    if i>>j&1:
      for l in L[j]:
        if H[l[0]-1] == 2:
          H[l[0]-1]=l[1]
        elif H[l[0]-1] != l[1]:
          f=1
          break
      if f:break
    else:
      H[j]=0
  if not f:
    h=max(h,H.count(1))
print(h)

Submission status: Wrong Answer

Solution code:
def judge(bit):
	"""一つ選びかたを固定"""
	b = 1
	for i in range(n):
		"""各Aiについて"""
		if (bit>>i) & 1 == 0:
			continue
		for k in range(len(li[i])):
			x = li[i][k][0] 
			y = li[i][k][1]
			if (bit>>x) & 1 == 1 and y == 0:
				b = 0
			if (bit>>x) & 1 == 0 and y == 1:
				b = 0
	return b
		
n = int(input())
li = []
for i in range(n):
	a = int(input())
	li_xy = [list(map(int, input().split())) for _ in range(a)]
	li.append(li_xy)
ans = 0
for bit in range(n):
	if judge(bit) == 1:
		count = 0
		for i in range(n):
			if (bit >>i) & 1 == 1:
				count += 1
		ans = max(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import defaultdict
    d = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = [int(x) for x in input().split()]
            d[i].append((x-1, y))

    ans = 0
    from itertools import product
    for ts in product([0, 1], repeat=n):
        if all([ts[i] == y for i in range(n) for x, y in d[i] if ts[i]==1]):
            ans = max(ans, sum(ts))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import defaultdict
    d = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = [int(x) for x in input().split()]
            d[i].append((x, y))

    ans = 0
    from itertools import product
    for ts in product([0, 1], repeat=n):
        if all([ts[i] == y for i in range(n) for x, y in d[i] if ts[i]==1]):
            ans = max(ans, sum(ts))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def get_flags(flag: int, n: int):
    res = []
    for _ in range(n):
        res.append((flag&1)==1)
        flag = flag >> 1
    return res


def is_valid(flags, d):
    n = len(flags)
    for i in range(n):
        for x, y in d[i]:
            if flags[x] != (y ^ (not flags[i])):
                return False
    return True


def main():
    from collections import defaultdict
    d = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = [int(x) for x in input().split()]
            d[i].append((x-1, y==1))
    # print(d)
    ans = 0
    for flag in range(0, 2**n):
        flags = get_flags(flag, n)
        if is_valid(flags, d):
            # print(flags)
            ans = max(ans, sum(flags))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def get_flags(flag: int, n: int):
    res = []
    for _ in range(n):
        res.append((flag&1)==1)
        flag = flag >> 1
    return res


def is_valid(flags, d):
    n = len(flags)
    for i in range(n):
        for x, y in d[i]:
            if (flags[i] and flags[x] != y) or (not flags[i] and flags[x] == y):
                return False
    return True


def main():
    from collections import defaultdict
    d = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = [int(x) for x in input().split()]
            d[i].append((x-1, y==1))
    ans = 0
    for flag in range(0, 2**n):
        flags = get_flags(flag, n)
        if is_valid(flags, d):
            ans = max(ans, sum(flags))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
H,L=[[] for _ in range(n)],[[] for _ in range(n)]

for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      H[i].append(x-1)
    else:
      L[i].append(x-1)
      
N=set(range(n))
ans=0
item={num:com  for num in range(1,n+1) for com in list(itertools.combinations(range(n),num))}
for k,v in item.items():
    num=k
    h=set(v)
    nh=N-h
    t=sum([H[i] for i in h],[])
    l=sum([L[i] for i in h],[])
    if set(t)<=h and set(l)<=nh:
      ans=max(ans,num)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
H,L=[[] for _ in range(n)],[[] for _ in range(n)]

for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      H[i].append(x-1)
    else:
      L[i].append(x-1)
      
N=set(range(n))
ans=0
item={num:com  for num in range(1,n+1) for com in list(itertools.combinations(range(n),num))}
for k,v in item.items():
    num=k
    h=set(v)
    nh=N-h
    t=sum([H[i] for i in h]+[L[i] for i in nh],[])
    l=sum([L[i] for i in h]+[H[i] for i in nh],[])
    if set(t)<=h and set(l)<=nh and len(set(t)&set(l))==0:
      ans=max(ans,num)
print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

n=int(input())
H,L=[[] for _ in range(n)],[[] for _ in range(n)]

for i in range(n):
  m=int(input())
  for j in range(m):
    x,y=map(int,input().split())
    if y==1:
      H[i].append(x-1)
    else:
      L[i].append(x-1)
      
N=set(range(n))
ans=0
item={num:com  for num in range(1,n+1) for com in list(itertools.combinations(range(n),num))}
for k,v in item.items():
    num=k
    h=set(v)
    nh=N-h
    t=sum([H[i] for i in h]+[L[i] for i in nh],[])
    l=sum([L[i] for i in h]+[H[i] for i in nh],[])
    if set(t)<=h and set(l)<=nh:
      ans=max(ans,num)
print(ans)