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())
table=[[None]*N for _ in range(N)]
for i in range(N):
    a=int(input())
    for j in range(a):
        x,y=map(int, input().split())
        table[i][x-1]=y

hito=[True]*N
for i in range(N-1):
    if hito[i]==False:
        continue
    for j in range(i+1,N):
        if table[i][j]==1:
            if table[j][i]==1 or table[j][i]==None:
                continue
            else:
                hito[i]=False
                break
        if table[i][j]==0:
            if table[j][i]==0 or table[j][i]==None:
                continue
            else:
                hito[j]=False
                break
    if hito[i]==True:
        for j in range(N):
            if table[i][j]==0:
                hito[j]=False
for i in range(N-1):
    if hito[i]==True and table[N-1][i]==0:
        hito[N-1]=False
    if hito[i]==False and table[N-1][i]==1:
        hito[N-1]=False

cnt=0
for i in range(N):
  if hito[i]==True:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    # input = sys.stdin.readline
    N = int(input())

    test = [dict() for _ in range(N)]

    count = 0

    for i in range(N):
        M = int(input())
        if M == 0:
            count += 1
        for _ in range(M):
            j, b = map(int, input().split())
            test[i][j-1] = bool(b)

    base_set = set(list(range(N)))

    for i in range(N):  # iが正直者と仮定
        honest = set()
        honest.add(i)
        lier = set()
        for j, b in test[i].items():  # 正直者の証言を作成
            if b:
                honest.add(j)
                for g, r in test[j].items():
                    if r:
                        honest.add(g)
                    else:
                        lier.add(g)
            else:
                lier.add(j)
        for j in honest:
            for g, r in test[j].items():
                if r:
                    honest.add(j)
                if not r:
                    lier.add(j)

        candidate = len(honest)
        for j in honest:  # 検証
            for g, r in test[j].items():
                if r:
                    if g in lier:
                        candidate = 0
                if not r:
                    if g in honest:
                        candidate = 0
        not_in = base_set - honest - lier
        for j in not_in:
            cand_n = 1
            for g, r in test[j].items():
                if r:
                    if g in lier:
                        cand_n = 0
                if not r:
                    if g in honest:
                        cand_n = 0
            candidate += cand_n

        count = max(count, candidate)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    person_list = [i for i in range(1, N+1)]
    
    ans_per_dic = {}
    ans_pattern_dic = {}
    honest_pattern = combinations(N, person_list)
    for i in range(1, N+1):
        ans_per_dic[i] = 0
        A = int(input())
        ans_list = []
        for a in range(A):
            l = input().rstrip().split(" ")
            l = [int(x) for x in l]
            ans_list.append(l)
        ans_pattern_dic[i] = ans_list
    
    cnt = 0
    
    for pattern in honest_pattern:
        temp_dic = ans_per_dic.copy()
        for p in pattern:
            temp_dic[p] = 1
        flag = True
        for person, answer in ans_pattern_dic.items():
            if judge(temp_dic, person, answer) == False:
                flag = False
                break
        if (flag == False):
            continue
        if cnt < len(pattern):
            cnt = len(pattern)
    print(cnt)
            
def judge(temp_dic, person, answer):
    if temp_dic[person] == 1:
        for ans in answer:
            if temp_dic[ans[0]] != ans[1]:
                return False
    if temp_dic[person] == 0:
        for ans in answer:
            if temp_dic[ans[0]] == ans[1]:
                return False
    return True
    
def combinations(n, guest_list):
    all_comb_list = []
    for i in range(1, 2**n):
        num = i
        c_list = []
        for j in range(n):
            if num % 2 == 1:
                c_list = [guest_list[n - 1 - j]] + c_list
            num = num // 2
        all_comb_list.append(c_list)
    return all_comb_list
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
Asgs = list()

def get_sgs(an):
    sgs = [list(map(int, input().split())) for i in range(an)]
    return sgs


for i in range(n):
    an = int(input())
    Asgs.append(get_sgs(an))

bits = [1] * n
end = False
# print(Asgs)
# sys.exit()
last_bits = [2] * n

cnt = 0
while cnt < 5:
    for i in range(n):
        
        # i人目の意見の個数
        for j in range(len(Asgs[i])):
            # bitsには正直者と登録されている人があるひと(正直者として登録されている)を不親切というなら
            if bits[i] == 1 and Asgs[i][j][1] == 0 and bits[Asgs[i][j][0]-1] ==1:
                
                #発言者もしくは発言対象者が偽
                bits[Asgs[i][j][0]-1] = 0
                """
                bits[i] = 0
                or
                bits[Asgs[i][j][0]-1] = 0
                """
                # print(i, j)
            # 正直者とされている人が不親切とされてる人を正直者と言っている場合,発言者は不親切である。
            if bits[i] == 1 and bits[Asgs[i][j][0]-1] == 0 and Asgs[i][j][1] == 1:
                bits[i] = 0
                # print('mj11')
            
    if last_bits == bits:
        cnt += 1
    last_bits = bits
        
# print(bits)
print(sum(bits))

Submission status: Wrong Answer

Solution code:
n = int(input())
b = []
c0 = [0]*n
c1 = [0]*n
for _ in range(n):
    a = int(input())
    for i in range(a):
        b = list(map(int, input().split()))
        for i in range(n):
            if b[0] == i+1 and b[1] ==1:
                c1[i] += 1 
            elif b[0] == i+1 and b[1] ==0:
                c0[i] += 1
d = 0
for j in range(n):
    if c1[j] != 0 and c0[j] !=0:
        d += min(c1[j],c0[j])
# if sum(c1[0])==0:
#     for k in range(n):
print(n - d if n-d>=0 else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())

NGlist = [0] * N
grouplist = [0]*N
ans = 0
for i in range(N):
    NGlist[i] = [0] * N
    grouplist[i] = [0] * N


for k in range(N):
    n = int(input())
    for j in range(n):
        x, y = map(int, input().split())
        if y == 0:
            NGlist[k][x-1] = 1
            NGlist[x - 1][k] = 1
        if y == 1:
            grouplist[k][x-1] = 1

for num in range(2 ** N):
    # print("num=")
    # print(num)
    group = set()
    newmember = set()
    for h in range(N):
        if h not in group and num % 2 == 1:
            group.add(h)
            newmember.add(h)
        num //= 2

    while (len(newmember) != 0):
        for s in list(newmember):
            for p in range(N):
                if grouplist[s][p] == 1 and p not in group:
                    group.add(p)
                    newmember.add(p)
                newmember.discard(p)

    len_group = len(group)
    # print(group)
    # if ans >= len_group:
    #    flag = 1
    flag = 0
    # print(group)
    for m in group:
        for t in group:
            if NGlist[m][t] == 1:
                flag = 1
                # break
        # if flag == 1:
            # break
    if flag == 0 and ans < len_group:
        ans = len_group

print(ans)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

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

ans = 0
for i in range(2**N):
    assumption = [int(num) for num in bin(i)[2:].rjust(N, '0')]
    appropriate = True
    for j, p in enumerate(assumption):
        for s in statements[j]:
            if (p == 1 and assumption[s[0] - 1] != s[1]) or (p == 0 and assumption[s[0] - 1] != abs(s[1]-1)):
                appropriate = False
                break
        else:
            continue
        break

    if appropriate and ans < assumption.count(1):
        ans = assumption.count(1)

print(ans)

Submission status: Wrong Answer

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

mat = []

for xy in xys:
    tmp = [2]*N
    for i in range(len(xy)):
        tmp[xy[i][0]-1] = xy[i][1]
    mat.append(tmp)

res = 0
for i in range(len(mat)):
    for j in range(len(mat[i])):
        if mat[i][j] == 1:
            if mat[j][i] == 1:
                res += 1
        if mat[i][j] == 0:
            if mat[j][i] == 0:
                res += 0.5


print(int(res))

Submission status: Wrong Answer

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

for i in range(N):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    list[i].append([x,y])
#print(list)

ans = 0
for i in range(2**N):
    flg = False
    do = [0] * N
    for j in range(N):
      if ((i >> j) & 1):
        do[j] = 1#ショウジキモノ＝１
    #print("do",do)
    P = [-1] * N
    for n in range(N):
      if flg:break
      for p in list[n]:
        if P[p[0]-1] == -1:
          #print(P[n])
          #print(p[0][1])
          if do[n] == 1:
            P[p[0]-1] = p[1]
          else:
            if p[1] == 1:
              P[p[0]-1] = 0
            else:
              P[p[0]-1] = 1
          if P[p[0]-1] != do[p[0]-1]:
            flg = True
        else:
          if P[p[0]-1] != do[p[0]-1]:
            flg = True
          #elif do[n] != P[p[0]-1]:
          #  flg = True
          elif do[n] == 1 and P[p[0]-1] != p[1]:
            flg = True
          elif do[n] == 0 and P[p[0]-1] == p[1]:
            flg = True
        if flg:break
    #print("P",P)
    if flg:
      continue
    #print("this")
    ans = max(ans,sum(do))
    #print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
H = []
for _ in range(n):
    H.append([-1]*n)
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        H[i][x-1] = y

ans = []
for i in range(n):
    c = 0
    for j in range(n):
        c += H[j][i]
    ans.append(c)
print(abs(sum(ans))//2)

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 flag is True:
        honest = bin_i.count('1')
        if honest > ans:
            ans = honest

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
honest = {}
honest1 = {}
for i in range(n):
    honest1[i+1] = []
dic = {}
for i in range(n):
    n1 = int(input())
    for j in range(n1):
        a, b = map(int, input().split())
        honest1[a].append(b)
        if i+1 in dic:
            dic[i+1].append([a, b])
        else:
            dic[i+1] = [[a, b]]

for i in honest1:
    if honest1[i].count(1) > honest1[i].count(0):
        honest[i] = True
        honest1[i] = False
    else:
        honest[i] = False
        honest1[i] = False
#print(honest, honest1)
for i in dic:
    if honest[i]:
        for j in dic[i]:
            honest[j[0]] = True if j[1] == 1 else False
            honest1[j[0]] = True
c = 0
for i in honest:
    if honest[i]:
        c += 1
if c > 0:
    for i in dic:
        if not honest[i]:
            f = 0
            for j in dic[i]:
                if j[1] != honest[j[0]]:
                    if honest1[j[0]]:
                        f = 1
                        break
            if f == 0:
                honest[i] = True
else:
    for i in dic:
        f = 0
        if not honest[i]:
            honest[i] = True
            for j in dic[i]:
                if j[0] == i:
                    if j[1] == 0:
                        f = 1
                        break
                else:
                    if j[1] != honest[j[0]]:
                        f = 1
                        break
        if f == 0:
            honest[i] = True
        else:
            honest[i] = False

c = 0
for i in honest:
    if honest[i]:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for i in range(N):
        a = int(input())
        for j in range(a):
            x, y = (int(i) for i in input().split())
            G[i].append((x-1, y))
            # 人iは人xのことをyと言っている

    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                cur += 1
                for j, y in G[i]:
                    if bit & (1 << j) and y == 0:
                        # 人jは正直者
                        good = False
                        break
                    elif not(bit & (1 << j)) and y == 1:
                        # 人jはうそつき
                        good = False
                        break
            else:
                # 人iはうそつき
                for j, y in G[i]:
                    if bit & (1 << j) and y == 1:
                        # 人jは正直者
                        good = False
                        break
                    elif not(bit & (1 << j)) and y == 0:
                        # 人jはうそつき
                        good = False
                        break
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
persons = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        persons[i].append([x-1, y])
ans = 0
amax = 0
b = [[] for _ in range(n)]
for i in range(2**n):
    tmp = list([i >> j & 1 for j in range(n)])
    flag = 0
    for q, k in enumerate(tmp):
        if k == 1:
            for person in persons[q]:
                b[person[0]].append(person[1])
        else:
            for person in persons[q]:
                if person[1] == 1:
                    b[person[0]].append(0)
                else:
                    b[person[0]].append(1)
    u = []
    for h, b1 in enumerate(b):
        if len(set(b1)) > 1:
            flag = 1
            break
        if set(b1):
            u.append(list(set(b1))[0])
        else:
            u.append(tmp[h])
    if flag == 0 and u == tmp:
        ans = tmp.count(1)
    if amax < ans:
        amax = ans
    ans = 0
    b = [[] for _ in range(n)]
print(amax)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []

for i in range(N):
    tmp = []
    A = int(input())
    for j in range(A):
        tmp.append(list(map(int, input().split())))
    S.append(tmp)

l = [2 for i in range(N)]
for i in S:
    for j in i:
        # 初めて言われた
        if l[j[0]-1] == 2:
            if j[1] == 1:
                l[j[0]-1] = 1
            else:
                l[j[0]-1] = -1
        # ２回目以降の人
        elif l[j[0]-1] == 1:
            if j[1] == 0:
                l[j[0]-1] -= 1
        elif l[j[0]-1] == -1:
            if j[1] == 1:
                l[j[0]-1] += 1
# 矛盾している場合
if sum(list(set(l))) == 0:
    print(0)
# 1は白確定
# 0は怪しい
# 2は言われてない
else:
    l = [1 if i == 2 else i for i in l]
    print(sum(l))

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
def checkp(p):
    cnt = 0
    for j in range(n):
        if len(p[j]) == 0: # 言及なし
            cnt += 1
        elif 1 in p[j] and 0 in p[j]: # 矛盾
            return -1
        elif 1 in p[j]: # 正直者
            cnt += 1
    return cnt

ans = 0
for i in itertools.product([0, 1], repeat=n):
    p = [set() for _ in range(n)]
    for j in range(n):
    #for xyi in xy:
        xyj = xy[j]
        p[j].add(i[j])
        for xyk in xyj:
            #print(xyj)
            if i[j] == 0:
                p[xyk[0]-1].add(-xyk[1] + 1)
            else:
                p[xyk[0]-1].add(xyk[1])
    #print(i, p, checkp(p))
    ans = max(ans, checkp(p))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
syouko = []
p = []
for i in range(n):
    a = int(input())
    s = []
    p.append([1]*n)
    for j in range(a):
        x,y = map(int,input().split())
        s.append([x-1,y])
    syouko.append(s)
for idx,lst in enumerate(syouko):
    for x,y in lst:
        p[idx][x] = y
ans_lst = [0]*n
for lst in p:
    for idx,i in enumerate(lst):
        ans_lst[idx] += i
m = max(ans_lst)
ans = 0
if m == n:
    for i in ans_lst:
        if i == m:
            ans += 1
else:
    if n % 2 == 0:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())
total = list()
good_person = list()
bad_person = list()
for i in range(1,n+1):
    t = int(input())
    A = list()
    for index in range(1,t+1):
        _input = input().split(" ")
        x = int(_input[0])
        y = int(_input[1])
        A.append((x, y))
    total.append(A)

for person in total:

    x = [x[0] for x in person]
    y = [y[1] for y in person]
    for index, a in enumerate(y):
        if a == 1:
            # good
            good_person.append(x[index])
        else:
            bad_person.append(x[index])
output = 0
# print(good_person)
# print(bad_person)
if sorted(good_person) == sorted(bad_person):
    output = 0
elif len(good_person) == 0:
    output = 1
elif len(good_person)< len(bad_person):
    output = 0
else:
    output = len(good_person) - len(bad_person)
print(output)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
xy = [0 for _ in range(n)]
for i in range(n):
    ai = int(input())
    xy[i] = [list(map(int , input().split())) for _ in range(ai)]

#print(xy)
#print(xy[0])
#print(xy[0][0])
def checkp(p):
    cnt = 0
    for j in range(n):
        if len(p[j]) == 0: # 言及なし
            cnt += 1
        elif 1 in p[j] and 0 in p[j]: # 矛盾
            return -1
        elif 1 in p[j]: # 正直者
            cnt += 1
    return cnt

ans = 0
for i in itertools.product([0, 1], repeat=n):
    p = [set() for _ in range(n)]
    for j in range(n):
    #for xyi in xy:
        xyj = xy[j]
        p[j].add(i[j])
        for xyk in xyj:
            #print(xyj)
            if i[j] == 0:
                p[xyk[0]-1].add(-xyk[1] + 1)
            else:
                p[xyk[0]-1].add(xyk[1])
    print(i, p, checkp(p))
    ans = max(ans, checkp(p))

print(ans)

Submission status: Wrong Answer

Solution code:
import sys 

n = int(input())
Asgs = list()

def get_sgs(an):
    sgs = [list(map(int, input().split())) for i in range(an)]
    return sgs


for i in range(n):
    an = int(input())
    Asgs.append(get_sgs(an))

bits = [1] * n
end = False
# print(Asgs)
# sys.exit()
last_bits = [2] * n

cnt = 0
while cnt < 5:
    for i in range(n):
        
        # i人目の意見の個数
        for j in range(len(Asgs[i])):
            # bitsには正直者と登録されている人があるひと(正直者として登録されている)を不親切というなら
            if bits[i] == 1 and Asgs[i][j][1] == 0 and bits[Asgs[i][j][0]-1] ==1:
                
                #発言者もしくは発言対象者が偽
                bits[Asgs[i][j][0]-1] = 0
                """
                bits[i] = 0
                or
                bits[Asgs[i][j][0]-1] = 0
                """
                # print(i, j)
            # 正直者とされている人が不親切とされてる人を正直者と言っている場合,発言者は不親切である。
            if bits[i] == 1 and bits[Asgs[i][j][0]-1] == 0 and Asgs[i][j][1] == 1:
                bits[i] = 0
                # print('mj11')
            
    if last_bits == bits:
        cnt += 1
    last_bits = bits
        
# print(bits)
print(sum(bits))

Submission status: Wrong Answer

Solution code:
total_test = int(input())
res = list()
trick_p = 0
for test in range(total_test):
	pres = list()
	total_people = int(input())
	trick_p = total_people
	for person in range(total_people):
		p, r = map(int, input().split())
		pres.append(r)
	validate = pres.count(1) - pres.count(0)	
	res.append(True) if validate >= 1 else res.append(False)
print(total_test - 1 if res.count(True) == 0 and trick_p == 1 else res.count(True))

Submission status: Wrong Answer

Solution code:
print(3)

Submission status: Wrong Answer

Solution code:
N=int(input())
arr_N=[]
for _ in range(N):
    A=int(input())
    arr_A=[]
    for _ in range(A):
        arr_A.append(list(map(int,input().split())))
    arr_N.append(arr_A)

import itertools
TF = (1,0)
TF_v = list(itertools.product(TF,repeat=N))
TF_v

def inv01(x):
    return 0 if x==1 else 1

ans = 0
for tf_v in TF_v:
    arr_tf=[]
    for i in range(N):
        if tf_v[i]==1:
            for t in arr_N[i]:
                arr_tf.append(tf_v[t[0]-1]==t[1])
        else:
            for t in arr_N[i]:
                arr_tf.append(tf_v[t[0]-1]==inv01(t[1]))
    if all(arr_tf):
        ans=max(ans,sum(tf_v))
print(ans)

Submission status: Wrong Answer

Solution code:
def hou2(tarrs, s, N):
    # print(tarrs, s, N)
    def checkTestimony(s, t):
        scopy = s[:]
        for i in range(len(s)):
            if s[i] != t[i] and s[i] != 0 and t[i] != 0:
                return None
            if t[i]:
                scopy[i] = t[i]
        return scopy

    def search(pos, N, s, acc):
        if pos < N:
            check_tp = checkTestimony(s, tarrs[pos])
            if s[pos] == 1:
                s[pos] = -1
                if check_tp:
                    # print(pos, " pre t:acc")
                    return search(pos + 1, N, check_tp, acc + 1)
                else:
                    # print(pos, " pre t:rej ", acc, s)
                    return 0
            if check_tp and s[pos] == 0:
                s[pos] = -1
                # print(pos, " ukn t:", check_tp)
                return max(search(pos + 1, N, check_tp, acc + 1), search(pos + 1, N, s, acc))
            else: # testimony unacceptable, assuming unkind
                # print(pos, " t:rej")
                s[pos] = -1
                return search(pos + 1, N, s, acc)
        else:
            # print("fin ", acc)
            return acc

    return search(0, N, s, 0)
    

if __name__ == "__main__":
    import sys
    in_arr = []
    for line in sys.stdin:
        in_arr.append([int(_) for _ in line.strip().split()])
    N = in_arr[0][0]
    i = 1
    tarrs = []
    s = [0] * N
    while i < len(in_arr):
        tnum = in_arr[i][0]
        tarr = [0] * N
        for j in range(tnum):
            x, y = in_arr[1 + j + i]
            tarr[x - 1] = 1 if y else -1 # -1 claimed unkind, 1 claimed honest
        if tarr[len(tarrs)] == -1: # claimed self to be unkind
            s[len(tarrs)] = -1
        tarrs.append(tarr)
        i += tnum + 1
    print(hou2(tarrs, s, N))

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

dicts = {i+1:{}  for i in range(N)}
un_dicts={i+1:{}  for i in range(N)}
for i in range(1,N+1):
    num = one_int()
    bits = ["0" for k in range(N)]
    un_bits = ["1" for k in range(N)]
    
    bits[int(i-1)]="1"
    un_bits[int(i-1)]="0"

    
    for j in range(num):
        hito, singi = two_int()
        bits[hito-1] = str(singi)
        
        if singi==1:
            un_bits[hito-1] = str(0)
        else:
            un_bits[hito-1] = str(1)
    
    dicts[i] = "".join(bits)
    un_dicts[i] = "".join(un_bits)



users = [j+1 for j in range(N)]
max_n=0
# 信じる人のループ
for i in dicts:
    all_syougens=[]
    all_or = 0
    old=0
    flg=False
    #信じる人の証言取得
    syougen = list(map(int, list(dicts[i])))
    
    # 信じる人の証言を各人の証言に適応
    count = 0
    for u,s in zip(users,syougen):
        si = dicts[u]
        #信じる人がうそつきだといったら反転
        if s==0:
            si = un_dicts[u]
        
        if count!=0:
            temps = old^int(si,2)

            if temps !=0:
                old = old^int(si,2)
                
                flg=False
            else:
                temp_si=si
                flg=True
            all_or = all_or | old
            
        else:
            old = int(si,2)
            all_or = old
        count+=1
    
    if flg:
        old =  old^int(temp_si,2)
    
    if old == 0:
        temp = bin(all_or)[2:].count("1")
        if temp >= max_n:
            max_n = temp
print(max_n)

Submission status: Wrong Answer

Solution code:
n = int(input())

hp = 0

for i in range(n):
  an = int(input())
  is_h = True
  for j in range(an):
    x, y = map(int, input().split(' '))
    if y == 0:
      is_h = False
  if is_h:
    hp += 1
print(hp)

Submission status: Wrong Answer

Solution code:
n = int(input())
persons = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        persons[i].append([x-1, y])
ans = 0
amax = 0
b = [[] for _ in range(n)]
for i in range(2**n):
    tmp = list([i >> j & 1 for j in range(n)])
    flag = 0
    for q, k in enumerate(tmp):
        if k == 1:
            for person in persons[q]:
                b[person[0]].append(person[1])
        else:
            for person in persons[q]:
                if person[1] == 1:
                    b[person[0]].append(0)
                else:
                    b[person[0]].append(1)
    u = []
    for h, b1 in enumerate(b):
        if len(set(b1)) > 1:
            flag = 1
        if set(b1):
            u.append(list(set(b1))[0])
        else:
            u.append(tmp[h])
    if flag == 0 and u == tmp:
        ans = tmp.count(1)
    if amax < ans:
        amax = ans
    ans = 0
    b = [[] for _ in range(n)]
print(amax)

Submission status: Wrong Answer

Solution code:
import sys
 
n = int(input())
c = [0 for _ in range(n)]
 
for i in range(n):
  a = int(input())
  for j in range(a):
    jump = 0
    x,y = map(int, input().split())
    if y == 1 :
      if c[i] != c[x-1] :
        if c[i] == 0 :
          c[i] = c[x-1]
          jump = 1
        elif c[x-1] == 0 :
          c[x-1] = c[i]
          jump = 1
        if jump == 0:
          print(0)
          sys.exit()
      if c[i] == 0 and c[x-1] == 0 :
        c[i] = 1
        c[x-1] = 1
    if y == 0 :
      if c[i] == c[x-1] :
        if c[i] == 0 or c[x-1] == 0 :
          c[i] = 1
          c[x-1] = -1
          jump = 1
        if jump == 0:
          print(0)
          sys.exit()
      if c[i] == 0 :
        c[i] = -1*c[x-1]
      elif c[x-1] == 0 :
        c[x-1] = -1*c[i]
      
print(c.count(1))

Submission status: Wrong Answer

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

for i in range(n):
    a.append(int(input()))  # 証言の個数

    syogen = [None] * (n)

    for j in range(a[-1]):
        xij, yij = map(int, input().split(' '))
        syogen[xij - 1] = yij

    syogens.append(syogen)

# それぞれの人からみた正直者の数
person_cnt = [None]*n

for i in range(n):
    #
    cnt = 0
    # 順に証言を見ていく
    # 自分を正直と仮定
    cnt += 1
    for j, syogen in enumerate(syogens[i]):
        # 正直という評価があれば
        if syogen == 1:
            # 自分が正直なとき、正直と評価した対象の人が自分を正直と評価していたら矛盾しない
            if syogens[j][i] == 1:
                cnt += 1
            # 自分が正直なとき、正直と評価した対象の人が自分を不親切と評価していたら矛盾する
            elif syogens[j][i] == 0:
                cnt -= 1

        # 自分が不親切と評価した相手が自分を不親切と評価していても矛盾しない
        if syogen == 0:
            if syogens[j][i] == 0:
                pass
                # cnt += 1

    person_cnt[i] = cnt

print(max(person_cnt))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
people = []
a = 0
for i in range(n):
  a = int(input())
  #people.append(a)
  for j in range(a):
    people.append(list(map(int,input().split())))
t_cnt = 0
f_cnt = 0
for order,tf in people:
  if tf == 1:
    t_cnt += 1
  else:
    f_cnt += 1
if t_cnt == 0:
  print(f_cnt//2)
elif t_cnt == f_cnt:
  print(0)
elif t_cnt > f_cnt:
  print(t_cnt)
else:
  print(t_cnt)
# T = np.full((n,people[1][0]),-1,np.int32)
# #T = [[None]*n]
# for order,tf in people:
#   T[order - 1][]
# print(T)
# cnt = 0
# for i in range(n):
#   for j in range(a):
#     #T[i][j] = people[0]
#     order,tf = people[cnt]
#     T[order - 1].append(tf)
#     cnt += 1
# ans = 0
# for ls in T:
#   if len(set(ls)) == 1:
#     if set(ls)[0] == 1:
#       ans += 2
#     else:
#       ans += 1
# print(ans)

Submission status: Wrong Answer

Solution code:
import itertools

N = int(input())
d = [0]*N
for i in range(N):
    A = int(input())
    d[i] = [list(map(int,input().split())) for _ in range(A)]
ans = 0
l = [0,1]
for s in itertools.product(l, repeat = N):
    c = [-1]*N
    flag = 1
    for i in range(N):
        if i != 0:
            if c[i] == s[i] or c[i] == -1:
                pass
            else:
                flag = -1
        if s[i] == 1:
            for a in d[i]:
                x = a[0]-1
                y = a[1]
                if c[x] == -1:
                    c[x] = y
                else:
                    if c[x] == y:
                        pass
                    else:
                        flag = -1
        else:
            for a in d[i]:
                x = a[0]-1
                y = a[1]
                if c[x] == -1:
                    if y == 1:
                        c[x] = 0
                    else:
                        c[x] = 1
                else:
                    if c[x] == y:
                        flag = -1
                    else:
                        pass
    if flag == 1:
        ans = max(ans,s.count(1))
print(ans)