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())
ret = {}
for i in range(0, n):
    a = int(input())
    ret[i] = [[], []]
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
 
dic = {}
 
 
def f(honest_p):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list: ', honest_p)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p]
    for i in ret[honest_p][0]:
        temp += f(i)
    return temp
 
 
ans = 0
for i in range(0, n):
    dic = {}
    honest = list((f(i)))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        # for k in ret[j][0]:
        #     if k in dishonest:
        #         val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ret = {}
for i in range(0, n):
    a = int(input())
    ret[i] = [[], []]
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
 
dic = {}
 
 
def f(honest_p):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list: ', honest_p)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p]
    for i in ret[honest_p][0]:
        temp += f(i)
    return temp
 
 
ans = 0
for i in range(0, n):
    dic = {}
    honest = list((f(i)))
    print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        # for k in ret[j][0]:
        #     if k in dishonest:
        #         val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ret = {}
for i in range(0, n):
    a = int(input())
    ret[i] = [[], []]
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
 
dic = {}
 
 
def f(honest_p):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list: ', honest_p)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p]
    for i in ret[honest_p][0]:
        temp += f(i)
    return temp
 
 
ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i)))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    t = int(input())
    for j in range(t):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ans = 0
for h in H:
    cnt = h.count("1")
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            cnt = 0
            break
    ans = max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N+1):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    t = int(input())
    for j in range(t):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:ANS.append(h)

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    t = int(input())
    for j in range(t):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:ANS.append(h)

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    for j in range(A[i]):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:ANS.append(h)

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    #証言しない人もいる
    if A[i] == 0:
        IXY.append([i,0,0])
        continue
    for j in range(A[i]):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:ANS.append(h)

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
for _ in range(n):
    a = []
    for _ in range(int(input())):
        a.append([int(i) for i in input().split()])
    A.append(a)

ans = 0
for i in range(2**n):
    
    bit = bin(i)[2:].zfill(n)[::-1]
    cnt = bit.count('1')
    b = False
    
    for i,t in zip(bit,A):
        for p in t:
            k,v = p
            
            if i == '0':
                if v == 1: v = 0
                else: v = 1
            
            if bit[k-1] != str(v):
                b = True
                cnt = 0
                break
        
        if b == True: break
    
    ans = max(ans,cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
for i in range(n):
    m=int(input())
    a.append(list(list(map(int,input().split())) for j in range(m)))
print(a)
ans=0
for i in range(2**n):
    r=1
    ib=list(format(i,"b").zfill(n))
    for j in range(n):
        if ib[j]=="1":
            for k in range(len(a[j])):
                if int(ib[a[j][k][0]-1])!=a[j][k][1]:
                    r=0
    if r==1:
        ans=max(ans,ib.count("1"))
print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j or j in honest or j in dishonest:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        # print(honest, dishonest, string)
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
for _ in range(n):
    a = []
    for _ in range(int(input())):
        a.append([int(i) for i in input().split()])
    A.append(a)

ans = 0
for i in range(2**n):
    
    tmp = [[[c for c in b] for b in a] for a in A]
    bit = bin(i)[2:].zfill(n)[::-1]
    """
    for a,b in zip(tmp,A):
        for c,d in zip(a,b):
            print(id(c),id(d))
    """
    for l,k in enumerate(bit):
        if k != '1':
            for m,p in enumerate(tmp[l]):
                v = p[1]
                if v == 1: tmp[l][m][1] = 0
                else: tmp[l][m][1] = 1
    
    cnt = bit.count('1')
    memo = [b for b in bit]
    b = False
    
    for t in tmp:
        for p in t:
            k,v = p
            if memo[k-1] != str(v):
                b = True
                cnt = 0
                break
        if b == True: break
    
    ans = max(ans,cnt)

print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        val = True
        for t in honest:
            if string[t] != 1:
                val = False
        for t in dishonest:
            if string[t] != 0:
                val = False
        for j in invalid:
            string[j] = 0
        # print(honest, dishonest, string)
        if not val and list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        val = True
        for t in honest:
            if string[t] != 1:
                val = False
        for t in dishonest:
            if string[t] != 0:
                val = False
        if not val and list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        for j in dishonest:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = ret[i][1]
    for a in honest:
        for b in ret[a][1]:
            if b not in dishonest:
                dishonest.append(b)
    # print('d', dishonest)
    dishonest = list(set(dishonest))
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    if honest_p in dic:
        return []
    dic[honest_p] = True
    # print('honest_list', honest_p, honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    temp = [honest_p] + honest_list
    for i in honest_list:
        temp += f(i, ret[i][0])
    return temp


ans = 0
for i in range(0, n):
    dic = {}
    honest = list(set(f(i, ret[i][0])))
    # print('h', honest)
    dishonest = []
    for i in honest:
        for j in ret[i][1]:
            if j not in dishonest:
                dishonest.append(j)
    # print('d', dishonest)
    invalid = []
    for j in range(0, n):
        if i == j:
            continue
        val = True
        for k in ret[j][1]:
            if k in honest:
                val = False
        for k in ret[j][0]:
            if k in dishonest:
                val = False
        if not val:
            invalid.append(j)
    # print('invalid', invalid)
    import itertools
    lst = list(itertools.product([0, 1], repeat=n))
    for string in lst:
        string = list(string)
        for j in invalid:
            string[j] = 0
        if list(set(honest) & set(dishonest)) == []:
            # print(string)
            ans = max(ans, string.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    #証言しない人もいる
    if A[i] == 0:
        continue
    for j in range(A[i]):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:ANS.append(h)

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

#人が一人しかいないとき
if N == 1:
    print(1)
    exit()

#人が2人以上いるとき
A = [0 for _ in range(N+1)]
l = [0,1]
H = []
#N人それぞれが正直か不誠実かの全パターンを生成
for i in range(2**N):
    S = str(bin(i)).zfill(N)
    H.append(S[2:].zfill(N))
#入力を受け取る
IXY = []
for i in range(1,N+1):
    A[i] = int(input())
    #証言しない人もいる
    if A[i] == 0:
        continue
    for j in range(A[i]):
        x,y = map(int,input().split())
        #i番目の人が「x番目の人はyである」と証言
        IXY.append([i,x,y])

ANS = []
for h in H:
    flg = True
    for ixy in IXY:
        i,x,y = ixy[0]-1,ixy[1]-1,ixy[2]
        if h[i] == "1" and h[x] != str(y):
            flg = False
            break
    if flg:l.append(ANS.append(h))

ans = 0
for a in ANS:
    ans = max(a.count("1"),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [[] for _ 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])

answer = 0
# 状態n
for n in range(2 ** N):
    copy_n = n
    count = 0
    while copy_n:
        if copy_n & 1:
            count += 1
        copy_n >>= 1
    # 矛盾が生じたときTrue
    flag = False
    # 人i
    for i in range(N):
        if flag:
            break
        # 不親切な人の証言は聞かない
        if (not (n >> i)) & 1:
            continue
        # jさん(正直者)の証言
        for x,y in xy[i]:
            # 証言と状態が違う場合
            if ((n >> x) & 1) != y:
                count = 0
                flag = True
                break

    if flag:
        continue
    else:
        answer = max(answer, count)
    
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
sentences = [[] for i in range(n)]

for i in range(n):
    nn = int(input())

    for j in range(nn):
        p, t = map(int, input().split())
        sentences[i].append([p - 1, t])

ans = 0
count = 0
for i in range(2 ** n):
    check = {}
    success = True
    for j in range(n):
        # print('i, j:', i, j, bin(i))
        if ((i >> j) & 1):
            sentence = sentences[j]

            for pp, tt in sentence:
                if pp in check:
                    if check[pp] == tt:
                        pass                         
                    else:
                        success = False
                        break
                else:
                    check[pp] = tt
            #print(check)
        else:
            sentence = sentences[j]

            for pp, tt in sentence:
                if pp in check:
                    if check[pp] != tt:
                        pass                         
                    else:
                        success = False
                        break
                else:
                    if tt == 1:
                        check[pp] = 0
                    else:
                        check[pp] = 1

        if success == False:
            # print('break')
            break

    if success:
        # print(check)
        count = bin(i).count('1')    
        ans = max(ans, count)

    # print('c, a:', count, ans)

print(ans)

Submission status: Wrong Answer

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

dic = {}


def f(honest_p, honest_list):
    # print('honest_list', honest_p, honest_list, dic)
    if ret[honest_p][0] == []:
        return []
    if honest_p not in dic:
        dic[honest_p] = True
    else:
        return []
    for i in honest_list:
        return honest_list + f(i, ret[i][0])


def nf(honest_p, honest_list):
    # print(honest_list)
    if ret[honest_p][1] == []:
        return []
    if honest_p in honest_list:
        return []
    for i in ret[honest_p][1]:
        return ret[i][1] + nf(i, honest_list + ret[i][1])


ans = 0
for i in range(0, n):
    dic = {}
    honest = [i] + f(i, ret[i][0])
    # print(i, 'a', set(honest))
    not_honest = ret[i][1]
    for j in honest:
        not_honest += ret[j][1]
    # print(i, 'b', set(not_honest))
    honest, not_honest = list(set(honest)), list(set(not_honest))
    # for j in range(0, n):
    #     if j not in honest and j not in not_honest:
    #         t_honest = ret[j][0] + f(j, [])
    #         t_not_honest = ret[j][1]
    #         for k in t_honest:
    #             t_not_honest += nf(k, t_not_honest)
    #         if list(set(honest) & set(t_not_honest)) == []:
    #             honest += list(set(t_honest))
    #         print(i, t_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(list(set(honest))))
    # print('c', ans)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**n):
    pat = []
    for j in range(n):
        pat.append((i>>j)%2)
    check = True
    for j in range(n):
        if pat[j]:
            for z in xy[j]:
                if pat[z[0]-1] != z[1]:
                    check = False
    if check:
        print(pat)
        ans = max(ans, sum(pat))
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

sw = []
N = int(input())
def create_ki(data):
    if len(data) == N:
        sw.append(data)
        return
    tmp = copy.copy(data)
    tmp.append(0)
    create_ki(tmp)
    tmp2 = copy.copy(data)
    tmp2.append(1)
    create_ki(tmp2)

create_ki([])

Speak = [{} for i in range(N)]
for i in range(N):
   A = int(input())
   for j in range(A):
       XY = input().split()
       Speak[i][XY[0]] = XY[1]

ans = 0
for peaples in sw: #0が真実で1が嘘
    true_list = [-1]*N
    isMujun = False
    for i in range(N):
         if isMujun:
             break
         for k,v in Speak[i].items():
             k = int(k)
             v = int(v)
             val = peaples[i]^v
             if peaples[k-1] == val:
                 isMujun = True
                 break
             elif (true_list[k-1] != -1) and (true_list[k-1] != val):
                 isMujun = True
                 break
             else:
                 true_list[k-1] = val
    if not isMujun:
        ans = max(ans, N-sum(peaples))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for _ in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x - 1, y))

def main():

    res = np.full(2 ** n, 1, np.int64).reshape(-1, 1)
    comb = np.arange(2 ** n).reshape(-1, 1)
    for i in range(n):
        for x, y in xy[i]:
            bl = (comb >> i & 1) ^ (comb >> x & 1 ^ y)
            res &= bl
    
    cand = np.where(res == 1)[0]
    ans = 0
    for c in cand:
        ans = max(ans, np.count_nonzero(c >> np.arange(n) & 1))
    return ans
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
katei=0
#katei[2:]
shou=[]
for i in range(N):
    n=int(input())
    tmp=[]
    for _ in range(n):
        h=list(map(int,input().split()))
        h[0]-=1
        tmp.append(h)
    shou.append(tmp)
#print(shou)
for i in range(2**N):
    flag=True
    tmp=str(bin(katei))[2:].zfill(N)
    #print(tmp)
    #print()
    for j in range(N):
        #print(tmp[j])
        for k in shou[j]:
            #print(k)
            
            if tmp[j]=="0":
                if tmp[k[0]]==str(k[1]):
                    #print("false")
                    flag=False
            else:
                if tmp[k[0]]==str(1-k[1]):
                    #print("falkse")
                    flag=False
            #print(state)
    if flag:
        #print("collect:",tmp)
        ans=max(ans,bin(katei).count("1"))
            
            
    katei+=1
print(ans)