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())
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 format(i,"015b")[-(say[j][k][0])] != str(say[j][k][1]):
                    judge = 0
        else:
            for k in range(len(say[j])):
                if format(i,"015b")[-(say[j][k][0])] == str(say[j][k][1]):
                    judge = 0
    
    if judge:
        for p in bin(i):
            if p == "1":
                c += 1
        a = max(a,c)
print(a)

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    ans=0
    for i in range(n):
        t=int(input())
        b=True
        for j in range(t):
            x,y=[int(i) for i in input().split()]
            if y==0:
                b=False
        if b:
            ans+=1
    print(ans)
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
data = []
for x in range(n):
    for y in range(int(input())):
        k, l = map(int, input().split())
        data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1,0], repeat=n):
    s = sum(list(i))
    for g in data:
        if i[g[0]] == 1 and i[g[1]] != g[2]:
            print("{}".format(g))
            s = 0
            break
    ans = max(ans, s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
A = []
for i in range(N):
    Ai = int(input())
    xyi = []
    for j in range(Ai):
        xyi.append(list(map(int, input().split())))
    A.append(Ai)
    xy.append(xyi)

ans = 0

for i in range(2**N):
    bin_i = format(i, '0' + str(N) + 'b')
    flag = True
    for n, c in enumerate(bin_i):
        if c == '1':
            for j in range(N):
                for k in range(A[j]):
                    if xy[j][k][0] == n+1:
                        if xy[j][k][1] == 0:
                            flag = False
                            break
                if not flag:
                    break
            if not flag:
                break
    if flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
data_dict = {}
data_re_dict = {}
for i in range(1, n + 1):
    temp = int(input())
    temp_list = []
    for j in range(0, temp):
        x, y = map(int, input().split())
        temp_list.append(x)
        temp_list.append(y)
        if x in data_re_dict:
            data_re_dict[x].append(i)
            data_re_dict[x].append(y)
        else:
            data_re_dict[x] = [i, y]
    data_dict[i] = temp_list
max_o_man = 0
for i in range(1, n + 1):
    check_dict = {}
    check_list = [-100] * n
    check_list[i-1] = 1
    check_dict[i] = 1
    count = 1
    flag = 1
    for j in range(0, len(data_dict[i]), 2):
        check_dict[data_dict[i][j]] = data_dict[i][j+1]
        check_list[data_dict[i][j]-1] = 0
        if data_dict[i][j+1] == 1:
            count += 1
    if i in data_re_dict:
        for j in range(0, len(data_re_dict[i]), 2):
            if data_re_dict[i][j] in check_dict:
                if check_dict[data_re_dict[i][j]] != data_re_dict[i][j+1]:
                    flag = 0
                    break
            else:
                check_dict[data_re_dict[i][j]] = data_re_dict[i][j + 1]
                check_list[data_re_dict[i][j]-1] = 0
                if data_re_dict[i][j+1] == 1:
                    count += 1
    if flag == 0:
        continue
    for k in range(0, n - 1):
        x = -1
        if 0 not in check_list:
            x = check_list.index(-100)
            check_dict[x + 1] = 1
            count += 1
        else:
            x = check_list.index(0)
        check_list[x] = 1
        for j in range(0, len(data_dict[x + 1]), 2):
            if data_dict[x + 1][j] in check_dict:
                if check_dict[x + 1] == 1:
                    if check_dict[data_dict[x + 1][j]] != data_dict[x + 1][j+1]:
                        flag = 0
                        break
                elif check_dict[x + 1] == 0:
                    if check_dict[data_dict[x + 1][j]] == data_dict[x + 1][j+1]:
                        flag = 0
                        break
            else:
                if check_dict[x + 1] == 1:
                    check_dict[data_dict[x + 1][j]] = data_dict[x + 1][j+1]
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 1:
                        count += 1
                elif check_dict[x + 1] == 0:
                    if data_dict[x + 1][j+1] == 1:
                        check_dict[data_dict[x + 1][j]] = 0
                    elif data_dict[x + 1][j+1] == 0:
                        check_dict[data_dict[x + 1][j]] = 1
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 0:
                        count += 1
        if flag == 0:
            continue
        if x + 1 in data_re_dict:
            for j in range(0, len(data_re_dict[x + 1]), 2):
                if data_re_dict[x + 1][j] in check_dict:
                    if check_dict[x + 1] == 1:
                        if check_dict[data_re_dict[x + 1][j]] != data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                    elif check_dict[x + 1] == 0:
                        if check_dict[data_re_dict[x + 1][j]] == data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                else:
                    if check_dict[x + 1] == 1:
                        check_dict[data_re_dict[x + 1][j]] = data_re_dict[x + 1][j+1]
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 1:
                            count += 1
                    elif check_dict[x + 1] == 0:
                        if data_re_dict[x + 1][j+1] == 1:
                            check_dict[data_re_dict[x + 1][j]] = 0
                        elif data_re_dict[x + 1][j+1] == 0:
                            check_dict[data_re_dict[x + 1][j]] = 1
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 0:
                            count += 1
            if flag == 0:
                break
    if flag == 1:
        if max_o_man < count:
            max_o_man = count
        if max_o_man == n:
            break
print(max_o_man)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
data_dict = {}
data_re_dict = {}
for i in range(1, n + 1):
    temp = int(input())
    temp_list = []
    for j in range(0, temp):
        x, y = map(int, input().split())
        temp_list.append(x)
        temp_list.append(y)
        if x in data_re_dict:
            data_re_dict[x].append(i)
            data_re_dict[x].append(y)
        else:
            data_re_dict[x] = [i, y]
    data_dict[i] = temp_list
max_o_man = 0
for i in range(1, n + 1):
    check_dict = {}
    check_list = [-100] * n
    check_list[i-1] = 1
    check_dict[i] = 1
    count = 1
    flag = 1
    for j in range(0, len(data_dict[i]), 2):
        check_dict[data_dict[i][j]] = data_dict[i][j+1]
        check_list[data_dict[i][j]-1] = 0
        if data_dict[i][j+1] == 1:
            count += 1
    if i in data_re_dict:
        for j in range(0, len(data_re_dict[i]), 2):
            if data_re_dict[i][j] in check_dict:
                if check_dict[data_re_dict[i][j]] != data_re_dict[i][j+1]:
                    flag = 0
                    break
            else:
                check_dict[data_re_dict[i][j]] = data_re_dict[i][j + 1]
                check_list[data_re_dict[i][j]-1] = 0
                if data_re_dict[i][j+1] == 1:
                    count += 1
    if flag == 0:
        continue
    for k in range(0, n - 1):
        x = -1
        if 0 not in check_list:
            x = check_list.index(-100)
            check_dict[x + 1] = 1
            count += 1
        else:
            x = check_list.index(0)
        check_list[x] = 1
        for j in range(0, len(data_dict[x + 1]), 2):
            if data_dict[x + 1][j] in check_dict:
                if check_dict[x + 1] == 1:
                    if check_dict[data_dict[x + 1][j]] != data_dict[x + 1][j+1]:
                        flag = 0
                        break
                elif check_dict[x + 1] == 0:
                    if check_dict[data_dict[x + 1][j]] == data_dict[x + 1][j+1]:
                        flag = 0
                        break
            else:
                if check_dict[x + 1] == 1:
                    check_dict[data_dict[x + 1][j]] = data_dict[x + 1][j+1]
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 1:
                        count += 1
                elif check_dict[x + 1] == 0:
                    if data_dict[x + 1][j+1] == 1:
                        check_dict[data_dict[x + 1][j]] = 0
                    elif data_dict[x + 1][j+1] == 0:
                        check_dict[data_dict[x + 1][j]] = 1
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 0:
                        count += 1
        if flag == 0:
            break
        if x + 1 in data_re_dict:
            for j in range(0, len(data_re_dict[x + 1]), 2):
                if data_re_dict[x + 1][j] in check_dict:
                    if check_dict[x + 1] == 1:
                        if check_dict[data_re_dict[x + 1][j]] != data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                    elif check_dict[x + 1] == 0:
                        if check_dict[data_re_dict[x + 1][j]] == data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                else:
                    if check_dict[x + 1] == 1:
                        check_dict[data_re_dict[x + 1][j]] = data_re_dict[x + 1][j+1]
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 1:
                            count += 1
                    elif check_dict[x + 1] == 0:
                        if data_re_dict[x + 1][j+1] == 1:
                            check_dict[data_re_dict[x + 1][j]] = 0
                        elif data_re_dict[x + 1][j+1] == 0:
                            check_dict[data_re_dict[x + 1][j]] = 1
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 0:
                            count += 1
            if flag == 0:
                break
    if flag == 1:
        if max_o_man < count:
            max_o_man = count
        if max_o_man == n:
            break
print(max_o_man)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
data_dict = {}
data_re_dict = {}
for i in range(1, n + 1):
    temp = int(input())
    temp_list = []
    for j in range(0, temp):
        x, y = map(int, input().split())
        temp_list.append(x)
        temp_list.append(y)
        if x in data_re_dict:
            data_re_dict[x].append(i)
            data_re_dict[x].append(y)
        else:
            data_re_dict[x] = [i, y]
    data_dict[i] = temp_list
max_o_man = 0
for i in range(1, n + 1):
    check_dict = {}
    check_list = [-100] * n
    check_list[i-1] = 1
    check_dict[i] = 1
    count = 1
    for j in range(0, len(data_dict[i]), 2):
        check_dict[data_dict[i][j]] = data_dict[i][j+1]
        check_list[data_dict[i][j]-1] = 0
        if data_dict[i][j+1] == 1:
            count += 1
    if i in data_re_dict:
        for j in range(0, len(data_re_dict[i]), 2):
            check_dict[data_re_dict[i][j]] = data_re_dict[i][j + 1]
            check_list[data_re_dict[i][j]-1] = 0
            if data_re_dict[i][j+1] == 1:
                count += 1
    flag = 1
    for k in range(0, n - 1):
        x = -1
        if 0 not in check_list:
            x = check_list.index(-100)
            check_dict[x + 1] = 1
            count += 1
        else:
            x = check_list.index(0)
        check_list[x] = 1
        for j in range(0, len(data_dict[x + 1]), 2):
            if data_dict[x + 1][j] in check_dict:
                if check_dict[x + 1] == 1:
                    if check_dict[data_dict[x + 1][j]] != data_dict[x + 1][j+1]:
                        flag = 0
                        break
                elif check_dict[x + 1] == 0:
                    if check_dict[data_dict[x + 1][j]] == data_dict[x + 1][j+1]:
                        flag = 0
                        break
            else:
                if check_dict[x + 1] == 1:
                    check_dict[data_dict[x + 1][j]] = data_dict[x + 1][j+1]
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 1:
                        count += 1
                elif check_dict[x + 1] == 0:
                    if data_dict[x + 1][j+1] == 1:
                        check_dict[data_dict[x + 1][j]] = 0
                    elif data_dict[x + 1][j+1] == 0:
                        check_dict[data_dict[x + 1][j]] = 1
                    check_list[data_dict[x + 1][j]-1] = 0
                    if data_dict[x + 1][j+1] == 0:
                        count += 1
        if flag == 0:
            break
        if x + 1 in data_re_dict:
            for j in range(0, len(data_re_dict[x + 1]), 2):
                if data_re_dict[x + 1][j] in check_dict:
                    if check_dict[x + 1] == 1:
                        if check_dict[data_re_dict[x + 1][j]] != data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                    elif check_dict[x + 1] == 0:
                        if check_dict[data_re_dict[x + 1][j]] == data_re_dict[x + 1][j+1]:
                            flag = 0
                            break
                else:
                    if check_dict[x + 1] == 1:
                        check_dict[data_re_dict[x + 1][j]] = data_re_dict[x + 1][j+1]
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 1:
                            count += 1
                    elif check_dict[x + 1] == 0:
                        if data_re_dict[x + 1][j+1] == 1:
                            check_dict[data_re_dict[x + 1][j]] = 0
                        elif data_re_dict[x + 1][j+1] == 0:
                            check_dict[data_re_dict[x + 1][j]] = 1
                        check_list[data_re_dict[x + 1][j]-1] = 0
                        if data_re_dict[x + 1][j+1] == 0:
                            count += 1
            if flag == 0:
                break
    if flag == 1:
        if max_o_man < count:
            max_o_man = count
        if max_o_man == n:
            break
print(max_o_man)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []

for i in range(n):
    a = int(input())
    temp = {}
    for j in range(a):
        x, y = map(int, input().split())
        temp[x] = y
    xy.append(temp)

ans = 0

for i in range(0, 2**n):
    # print('\n', i, bin(i))
    isValid = True
    temp = 0

    for k in range(len(xy)):
        hMap = xy[k]
        kBit = (i >> k) & 1
        # print('k:', k, 'kBit:', kBit)
        if kBit == 1:
            # print('hMap is correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be same')
                if not ((i >> (key-1)) & 1) == value:
                    # print('paradox!')
                    isValid = False
                    break
        else:
            # print('hMap is NOT correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be different')
                if not ((i >> (key-1)) & 1) != value:
                    # print('paradox!')
                    isValid = False
                    break
    if isValid:
        for j in range(n):
            # print('Check digit:', j)
            jBit = (i >> j) & 1
            # print('bit:', jBit)
            if jBit == 1:
                temp += 1
        ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []

for i in range(n):
    a = int(input())
    temp = {}
    for j in range(a):
        x, y = map(int, input().split())
        temp[x] = y
    xy.append(temp)

ans = 0

for i in range(0, 2**n):
    # print('\n', i, bin(i))
    isValid = True
    temp = 0

    for k in range(len(xy)):
        hMap = xy[k]
        kBit = (i >> k) & 1
        # print('k:', k, 'kBit:', kBit)
        if kBit == 1:
            # print('hMap is correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be same')
                if not ((i >> (key-1)) & 1) == value:
                    # print('paradox!')
                    isValid = False
                    break
            else:
                break
        else:
            # print('hMap is NOT correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be different')
                if not ((i >> (key-1)) & 1) != value:
                    # print('paradox!')
                    isValid = False
                    break
            else:
                break
    if isValid:
        for j in range(n):
            # print('Check digit:', j)
            jBit = (i >> j) & 1
            # print('bit:', jBit)
            if jBit == 1:
                temp += 1
        ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
# 全探索
# 証言が矛盾していないかどうかをチェックする
# 証言の妥当性のみを見れば良い感じ？
N = int(input())
xy = []
for i in range(N):
    a = int(input())
    b = []
    for j in range(a):
        x, y = list(map(int, input().split()))
        b.append([x - 1, y])
    xy.append(b)

review = [[] for _ in range(N)]

# print(xy)

for i in range(N):
    M = len(xy[i])
    for j in range(M):
        review[xy[i][j][0]].append(xy[i][j][1])

# print(review)
ans = 0
for i in range(N):
    if len(review[i]) == 0:
        ans += 1
    elif len(review[i]) == 1 and review[i][0] == 1:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []

for i in range(n):
    a = int(input())
    temp = {}
    for j in range(a):
        x, y = map(int, input().split())
        temp[x] = y
    xy.append(temp)

ans = 0

for i in range(0, 2**n):
    # print('\n', i, bin(i))
    isValid = True
    temp = 0

    for k in range(len(xy)):
        hMap = xy[k]
        kBit = (i >> k) & 1
        # print('k:', k, 'kBit:', kBit)
        if kBit == 1:
            # print('hMap is correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be same')
                if not (i >> (key-1)) & 1 == value:
                    # print('paradox!')
                    isValid = False
                    break
            else:
                break
        else:
            # print('hMap is NOT correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be different')
                if not (i >> (key-1)) & 1 != value:
                    # print('paradox!')
                    isValid = False
                    break
            else:
                break
    if isValid:
        for j in range(n):
            # print('Check digit:', j)
            jBit = (i >> j) & 1
            # print('bit:', jBit)
            if jBit == 1:
                temp += 1
        ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []

for i in range(n):
    a = int(input())
    temp = {}
    for j in range(a):
        x, y = map(int, input().split())
        temp[x] = y
    xy.append(temp)

ans = 0

for i in range(0, 2**n):
    # print('\n', i, bin(i))
    isValid = True
    temp = 0

    for k in range(len(xy)):
        hMap = xy[k]
        kBit = (i >> k) & 1
        # print('k:', k, 'kBit:', kBit)
        if kBit == 1:
            # print('hMap is correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be same')
                if not (i >> (key-1)) & 1 == value:
                    # print('paradox!')
                    isValid = False
                    break
        else:
            # print('hMap is NOT correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be different')
                if not (i >> (key-1)) & 1 != value:
                    # print('paradox!')
                    isValid = False
                    break
    if isValid:
        for j in range(n):
            # print('Check digit:', j)
            jBit = (i >> j) & 1
            # print('bit:', jBit)
            if jBit == 1:
                temp += 1
        ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []

for i in range(n):
    a = int(input())
    temp = {}
    for j in range(a):
        x, y = map(int, input().split())
        temp[x] = y
    xy.append(temp)

ans = 0

for i in range(0, 2**n):
    # print('\n', i, bin(i))
    isValid = True
    temp = 0

    for k in range(len(xy)):
        hMap = xy[k]
        kBit = (i >> k) & 1
        # print('k:', k, 'kBit:', kBit)
        if kBit == 1:
            # print('hMap is correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be same')
                if not (i >> (key-1)) & 1 == value:
                    # print('paradox!')
                    isValid = False
                    break
        else:
            # print('hMap is NOT correct:', hMap)
            for key, value in hMap.items():
                # print(key, value, (i >> (key-1)) & 1, 'must be different')
                if not (i >> (key-1)) & 1 != value:
                    # print('paradox!')
                    isValid = False
                    break
    if isValid:
        for j in range(n):
            # print('Check digit:', j)
            jBit = (i >> j) & 1
            # print('bit:', jBit)
            if jBit == 1:
                temp += 1

    ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2**n):
  for j in range(n):
    flag=True
    tp=[-1]*n
    for x,y in XYS[j]:
      if i<<j&0:
        continue
      if i<<(x-1)!=y:
        flag=False
        break
      else:
        if tp[x-1]==-1:
          tp[x-1]=y
        elif tp[x-1]!=y:
          flag=True
          break
    if flag:
      ans+=1
print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2**n):
  for j in range(n):
    flag=True
    tp=[-1]*n
    for x,y in XYS[j]:
      if i>>j&1:
        pass
      else:
        x,y=x,(y+1)%2
      if i<<(x-1)!=y:
        flag=False
        break
      else:
        if tp[x-1]==-1:
          tp[x-1]=y
        elif tp[x-1]!=y:
          flag=True
          break
    if flag:
      ans+=1
print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2**n):
  for j in range(n):
    flag=True
    tp=[-1]*n
    for x,y in XYS[j]:
      if i<<j&1:
        pass
      else:
        x,y=x,(y+1)%2
      if i<<(x-1)!=y:
        flag=False
        break
      else:
        if tp[x-1]==-1:
          tp[x-1]=y
        elif tp[x-1]!=y:
          flag=True
          break
    if flag:
      ans+=1
print(ans)

Submission status: Wrong Answer

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

ans=0
for i in range(2**n):
  for j in range(n):
    flag=True
    for x,y in XYS[j]:
      if i<<j&1:
        pass
      else:
        x,y=x,(y+1)%2
      if i<<(x-1)!=y:
        flag=False
        break
    if flag:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def inputlist():
	n=int(input())
	A=list()
	for i in range(n):
		Ai = int(input())
		s=list()
		for i in range(Ai):
			s += input().split()
		s = [int(i) for i in s]
		A.append(s)
	return A

A=inputlist()
n=len(A)
ans=0
for i in range(2**n):
	bit_str = str(format(i,'015b'))
	check = ['0']*15
	for j in range(n):
		if ((i >> j) & 1):
			for k in range(0,len(A[j]),2):
				if (A[j][k+1]):
					check[-1*A[j][k]] = '1'
				if (not A[j][k+1])&(bool(check[-1*A[j][k]])):
					check = ['0']*15
					break
	if (''.join(check) == bit_str):
		ans = max(ans,bit_str.count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
def inputlist():
	n=int(input())
	A=list()
	for i in range(n):
		Ai = int(input())
		s=list()
		for i in range(Ai):
			s += input().split()
		s = [int(i) for i in s]
		A.append(s)
	return A

A=inputlist()
n=len(A)
ans=0
for i in range(2**n):
	bit_str = str(format(i,'015b'))
	check = ['0']*15
	for j in range(n):
		if ((i >> j) & 1):
			for k in range(0,len(A[j]),2):
				if (A[j][k+1]):
					check[-1*A[j][k]] = '1'
	if (''.join(check) == bit_str):
		ans = max(ans,bit_str.count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
A = []
for i in range(N):
    Ai = int(input())
    xyi = []
    for j in range(Ai):
        xyi.append(list(map(int, input().split())))
    A.append(Ai)
    xy.append(xyi)

ans = 0

for i in range(2**N):
    bin_i = format(i, '0' + str(N) + 'b')
    flag = True
    for n, c in enumerate(bin_i):
        if c == '1':
            for j in range(N):
                for k in range(A[j]):
                    if xy[j][k][0] == n:
                        if xy[j][k][1] == 0:
                            flag = False
                            break
                if not flag:
                    break
            if not flag:
                break
    if flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
x = [[] for i in range(N)]
y = [[] for i in range(N)]
for i in range(N):
    A.append(int(input()))
    for j in range(A[i]):
        tmpX, tmpY = map(int, input().split())
        x[i].append(tmpX-1)
        y[i].append(tmpY)
ans = 0
if N == 1:
    print(1)
    exit()

for case in range(2**N):
    flag = True
    case = str(bin(case))[2:]
    honest = [i for i, x in enumerate(case) if x == '1']
    #print(honest)
    for hon in honest:
        for j, other in enumerate(x[hon]):
            #print(other in honest)
            if (other in honest) and (y[hon][j] == 0):
                flag = False

            elif (not(other in honest)) and (y[hon][j] == 1):
                flag = False

            else:
                continue
    #print(flag)
    if flag:
        ans = max(ans, len(honest))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
x = [[] for i in range(N)]
y = [[] for i in range(N)]
for i in range(N):
    A.append(int(input()))
    for j in range(A[i]):
        tmpX, tmpY = map(int, input().split())
        x[i].append(tmpX-1)
        y[i].append(tmpY)
ans = 0
for case in range(2**N):
    flag = True
    case = str(bin(case))[2:]
    honest = [i for i, x in enumerate(case) if x == '1']
    #print(honest)
    for hon in honest:
        for j, other in enumerate(x[hon]):
            #print(other in honest)
            if (other in honest) and (y[hon][j] == 0):
                flag = False

            elif (not(other in honest)) and (y[hon][j] == 1):
                flag = False

            else:
                continue
    #print(flag)
    if flag:
        ans = max(ans, len(honest))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
A = []
for i in range(N):
    Ai = int(input())
    xyi = []
    for j in range(Ai):
        xyi.append(list(map(int, input().split())))
    A.append(Ai)
    xy.append(xyi)

ans = 0

for i in range(2**N):
    bin_i = format(i, '4b')
    flag = True
    for n, c in enumerate(bin_i):
        if c == '1':
            for j in range(N):
                for k in range(A[j]):
                    if xy[j][k][0] == n:
                        if xy[j][k][1] == 0:
                            flag = False
                            break
                if not flag:
                    break
            if not flag:
                break
    if flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
A = []
for i in range(N):
    Ai = int(input())
    xyi = []
    for j in range(Ai):
        xyi.append(list(map(int, input().split())))
    A.append(Ai)
    xy.append(xyi)

ans = 0

for i in range(2**N+1):
    bin_i = format(i, '4b')
    flag = True
    for n, c in enumerate(bin_i):
        if c == '1':
            for j in range(N):
                for k in range(A[j]):
                    if xy[j][k][0] == n:
                        if xy[j][k][1] == 0:
                            flag = False
                            break
                if not flag:
                    break
    if flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)