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())
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]]==k[1]:
                    #print("false")
                    flag=False
            else:
                if tmp[k[0]]==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)

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)


def f(honest_p, honest_list):
    # print(honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    if honest_p in honest_list:
        return []
    for i in ret[honest_p][0]:
        return ret[i][0] + f(i, honest_list + 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):
    honest = ret[i][0] + f(i, [])
    # print('a', honest)
    not_honest = ret[i][1]
    for j in honest:
        not_honest += nf(j, not_honest)
    # print('b', not_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())
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)


def f(honest_p, honest_list):
    # print(honest_list)
    if ret[honest_p][0] == []:
        return [honest_p]
    if honest_p in honest_list:
        return []
    for i in ret[honest_p][0]:
        return ret[i][0] + f(i, honest_list + 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):
    honest = f(i, [])
    # print('a', honest)
    not_honest = ret[i][1]
    for j in honest:
        not_honest += nf(j, not_honest)
    # print('b', not_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:
import itertools
N = int(input())
As = []
data = []

for i in range(N):
    As.append(int(input()))
    for k in range(As[i]):
      x,y = [int(j) for j in input().split()]
      data.append(x)
      data.append(y)

searched = [False]*N
TF = [-1]*N

#print("len"+str(len(data)))

for i in range(0,int(len(data)),2):
    if searched[data[i]-1]==False:
        searched[data[i]-1] = True
        TF[data[i]-1] = data[i+1]
    else:
        TF[data[i]-1] != data[i+1]
        TF[data[i]-1] = 0
    print(data[i])
    
count = 0
for i in range(int(len(TF))):
    if TF[i]==1:
        count += 1

#print(searched)
#print(TF)
print(count)

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)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        # print(p, ret[p])
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    # print(honest, not_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
    for i in range(0, n):
        if i not in honest and i not in not_honest:
            t_honest, t_not_honest = [i], []
            for h in ret[i][0]:
                t_honest.append(h)
            for d in ret[i][1]:
                t_not_honest.append(d)
            t_honest = list(set(t_honest))
            t_not_honest = list(set(t_not_honest))
            if list(set(honest) & set(t_not_honest)) == []:
                honest = list(set(honest + t_honest))
                ans = max(ans, len(honest))
print(ans)

Submission status: Wrong Answer

Solution code:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    A = [[] for _ in range(N)]
    for i in range(N):
        for _ in range(inputInt()):
            A[i].append(inputIntList())
    ret = 0
    for i in range(2 ** N):
        bits = [i >> j & 1 for j in range(N)]
        for i, a in enumerate(A):
            if bits[i] == 0:
                continue
            for x, y in a:
                if bits[x - 1] == y:
                    continue
                break
            else:
                ret = max(ret, sum(bits))
    return ret


if __name__ == "__main__":
    print(main())

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)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        # print(p, ret[p])
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    # print(honest, not_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
    for i in range(0, n):
        if i not in honest and i not in not_honest:
            t_honest, t_not_honest = [], []
            for h in ret[i][0]:
                t_honest.append(h)
            for d in ret[i][1]:
                t_not_honest.append(d)
            t_honest = list(set(t_honest))
            t_not_honest = list(set(t_not_honest))
            if list(set(honest) & set(t_not_honest)) == []:
                honest = list(set(honest + t_honest))
                ans = max(ans, len(honest))
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)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        # print(p, ret[p])
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    # print(honest, not_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
xyz =[]
a_list = []
ans = ['None']*n

count = 0
for _ in range(n):
    a = int(input())
    a_list.append(a)
    for i in range(a):
        x,y = map(lambda x: int(x),input().split())
        xy.append([x,y])
    xyz.append(xy)
    xy = []

for j in range(n):
    for k in range(a_list[j]) :
        hoge = xyz[j][k][:]
        if ans[hoge[0]-1] == 'None':
            ans[hoge[0]-1] = hoge[1]
        elif ans[hoge[0]-1] != hoge[1]:
            count+= 1
if ans == [0]*n :
    print(1)
else:
    print(n - count)

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)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        # print(p, ret[p])
        if p not in ret:
            continue
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    # print(honest, not_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
    for i in range(0, n):
        if i not in honest and i not in not_honest:
            t_honest, t_not_honest = [], []
            for h in ret[i][0]:
                t_honest.append(h)
            for d in ret[i][1]:
                t_not_honest.append(d)
            t_honest = list(set(t_honest))
            t_not_honest = list(set(t_not_honest))
            if list(set(honest) & set(t_not_honest)) == []:
                honest = list(set(honest + t_honest))
                ans = max(ans, len(honest))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = []
xyz =[]
a_list = []
ans = [1]*n

count = 0
for _ in range(n):
    a = int(input())
    a_list.append(a)
    for i in range(a):
        x,y = map(lambda x: int(x),input().split())
        xy.append([x,y])
    xyz.append(xy)
    xy = []

for j in range(n):
    for k in range(a_list[j]) :
        hoge = xyz[j][k][:]
        if ans[hoge[0]-1] != hoge[1]:
            count+= 1

if ans == [1]*n :
    print(1)
else:
    print(n - count)

Submission status: Wrong Answer

Solution code:
# 2019/12/09

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

ans=0
for bit in range(1,2**n):
    ret=[1]*n
    for idx in range(n):
        if bit&(1<<idx):
            ret=list(map(lambda x,y:(x&y),xy[idx],ret))
    BIT=bin(bit).count('1')
    RET=''.join(map(str,ret)).count('1')
    if BIT==RET:
        ans=max(ans,BIT)

print(ans)

Submission status: Wrong Answer

Solution code:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    xy = [[] for _ in range(N)]
    for i in range(N):
        A = inputInt()
        for _ in range(A):
            xy[i].append(inputIntList())
    ret = 0
    for i in range(2 ** N):
        state = [-1 for _ in range(N)]
        bit = format(i, "b").rjust(N, "0")
        for i, j in enumerate(bit):
            if j == "1":
                state[i] = 1
                for x, y in xy[i]:
                    if state[x - 1] == -1:
                        state[x - 1] = y
                    elif state[x - 1] != y:
                        break
                else:
                    # print(state)
                    continue
                break
        else:
            for i, s in enumerate(state):
                if s == 1:
                    for x, y in xy[i]:
                        if state[x - 1] != y:
                            break
                    else:
                        continue
                    break
            else:
                ret = max(ret, sum(state))
    return ret


if __name__ == "__main__":
    print(main())

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)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        # print(p, ret[p])
        if p not in ret:
            continue
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    # print(honest, not_honest)
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
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())
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        if p not in ret:
            continue
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, len(honest))
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())
        if y == 1:
            ret[i][0].append(x)
        elif y == 0:
            ret[i][1].append(x)
ans = 0
for u in ret:
    i = ret[u]
    num = 1 + len(i[0])
    honest = [u] + i[0]
    not_honest = i[1]
    for p in i[0]:
        if p not in ret:
            continue
        for h in ret[p][0]:
            honest.append(h)
        for d in ret[p][1]:
            not_honest.append(d)
    honest = list(set(honest))
    not_honest = list(set(not_honest))
    if list(set(honest) & set(not_honest)) == []:
        ans = max(ans, num)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
for i in range(n):
    B=["0"]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    B[i]="*"
    A.append(B)
ans=0
for i in range(2**n):
    num=list(format(i,"b").zfill(n))
    cnt,flag=0,1
    for k,j in enumerate(num):
        A[k][k]=j
        if A[k]==num and j=="1":
            cnt +=1
        elif (A[k]==num and j=="0") or (A[k]!=num and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n  = int(input())
count_one = 0
count_zero = 0
swap = 0

if 1 <= n <= 15:
  for i in range(0,n):
    i = int(input())
    for j in range(0,i):
      x,y= map(int, input().strip().split())
      if y == 1:
        swap = y
        count_one = count_one  + 1
      else:
        if swap == y:
          if swap == 0:
            count_zero  = count_zero  + 1
        else:
          if count_one < 2:
            count_zero = 0
            count_one = 0 
      swap = y
          
     
if count_zero >= 1:
  print(1)
else:
  print(count_one)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[]
for i in range(n):
    B=["0"]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    B[i]="*"
    A.append(B)
ans=0
for i in range(2**n):
    num=list(format(i,"b").zfill(n))[::-1]
    cnt,flag=0,1
    for k,j in enumerate(num):
        A[k][k]=j
        if A[k]==num and j=="1":
            cnt +=1
        elif (A[k]==num and j=="0") or (A[k]!=num and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=5

for i in range(n):
  print(i>>1)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy
n=int(input())
A=[["0" for i in range(n)] for j in range(n)]
for i in range(n):
    A[i][i]="."
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        A[i][x-1]=str(y)
#print(np.array(A))
ans=0
for i in range(2**n):
    num=list(format(i,"b").zfill(n))[::-1]
    B=copy.deepcopy(A)
    cnt=0
    for j in range(n):
        B[j][j]=num[j]
        if B[j]==num and num[j]=="1":
            cnt +=1
        elif B[j]!=num and num[j]=="1":
            cnt=0
            break
    ans=max(ans,cnt)
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 j in range(A):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    for n in range(N):
        if (b >> n) & 1:
            for x,y in xy[n]:
                if y != b >> (x-1):
                    break
            else:
                continue
            break
    else:
        ans = max(ans,bin(b).count("1"))
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 j in range(A):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"000000000000000")[2+i]) for i in range(N)]
    #lis は0,1で表される不親切、正直者
    for n,l in enumerate(lis):
        #nは今見ている人、lは1なら正直者
        if l:
            for x,y in xy[n]:
                if y != lis[x-1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans,lis.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
XY = []
ans = 0
for i in range(n):
  a = int(input())
  XY.append([])
  for j in range(a):
    XY[i].append(list(map(int,input().split())))
for i in range(2**n):
  i = format(i, 'b')
  i = i.zfill(n)
  temp = i.count("1")
  temp2 = 0
  print(i)
  for j in range(n):
    if i[j] == "1":
      for k in range(len(XY[j])):
        if str(XY[j][k][1]) != i[XY[j][k][0]-1]:
          temp2 = 1
          break
  if temp2 == 0:
    if ans < temp:
      ans = temp
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    if not A:
        continue
    for j in range(A):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"000000000000000")[2+i]) for i in range(N)]
    #lis は0,1で表される不親切、正直者
    for n,l in enumerate(lis):
        #nは今見ている人、lは1なら正直者
        if l:
            for x,y in xy[n]:
                if y == lis[x-1]:
                    continue
                else:
                    break
            else:
                continue
        else:
            continue
        break
    else:
        ans = max(ans,lis.count(1))
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 j in range(A_):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"000000000000000")[2+i]) for i in range(N)]
    #lis は0,1で表される不親切、正直者
    for n,l in enumerate(lis):
        #nは今見ている人、lは1なら正直者
        if l:
            for x,y in xy[n]:
                if y == lis[x-1]:
                    continue
                else:
                    break
            else:
                continue
        else:
            continue
        if xy[n] == []:
            continue
        else:
            break
    else:
        ans = max(ans,lis.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
xy = [[] for _ in range(N)]
for i in range(N):
    A_ = int(input())
    for j in range(A_):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"000000000000000")[2+i]) for i in range(N)]
    for n,l in enumerate(lis):
        if l:
            for x,y in xy[n]:
                if y == lis[x-1]:
                    continue
                else:
                    break
            else:
                continue
        else:
            continue
        break
    else:
        ans = max(ans,lis.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
xy = [[] for _ in range(N)]
for i in range(N):
    A_ = int(input())
    for j in range(A_):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"000000000000000")[2+i]) for i in range(N)]
    for n,l in enumerate(lis):
        if l:
            for x,y in xy[n]:
                if y == lis[x-1]:
                    continue
                else:
                    break
            else:
                continue
            break
    else:
        ans = max(ans,lis.count(1))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
E = []
for n in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        E.append((n, x - 1, y))
ans = 0
for k in range((1 << N) - 1, -1, -1):
    status = [(k >> i) & 1 for i in range(N)]
    no_paradox = True
    for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] == yb):
            no_paradox = False
            break
    if no_paradox:
        ans = max(ans, sum(status))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
xy = [[] for _ in range(N)]
for i in range(N):
    A_ = int(input())
    for j in range(A_):
        xy_ = tuple(map(int,input().split()))
        xy[i].append(xy_)

bN = 2**N
ans = 0
for b in range(bN):
    lis = [int((bin(b)+"00000000000000")[2+i]) for i in range(N)]
    for n,l in enumerate(lis):
        if l:
            for x,y in xy[n]:
                if y == lis[x-1]:
                    continue
                else:
                    break
            else:
                continue
            break
    else:
        ans = lis.count(1)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
E = []
for n in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        E.append((n, x - 1, y))
ans = 0
for k in range((1 << N)):
    status = [(k >> i) & 1 for i in range(N)]
    no_paradox = True
    for Xa, Xb, yb in E:
        if (status[Xa] == 1 and status[Xb] == yb):
            no_paradox = False
            break
    if no_paradox:
        ans = max(ans, sum(status))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
from itertools import product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = True
  for j in range(len(L)):
    #jの情報は、(hito=x, singi = y=1,0)
    #iの情報は、(singi = (1/0,...,1/0))
    for x,y in L[j]:
      #jさんの情報      
      #i[j] :sinngi　正解
      #y:sinngi　を変換
      if i[j]==0:
        if y == 0:
          y = 1
        else:
          y = 0
      if i[x-1]!=y:
        flg = False
        break
  if flg:
    cnt = max(cnt,sum(i))
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
from itertools import product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = True
  print(i)
  for j in range(len(L)):
    #jの情報は、(hito=x, singi = y=1,0)
    #iの情報は、(singi = (1/0,...,1/0))
    for x,y in L[j]:
      #jさんの情報      
      #i[j] :sinngi　正解
      #y:sinngi　を変換
      if i[j]==0:
        if y == 0:
          y = 1
        else:
          y = 0
      if i[x-1]!=y:
        flg = False
        break
  if flg:
    cnt = max(cnt,sum(i))
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
  A = int(input())
  LA = []
  for j in range(A):
    LA.append(list(map(int,input().split())))
  L.append(LA)
from itertools import product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = True
  for j in range(len(L)):
    #jの情報は、(hito=x, singi = y=1,0)
    #iの情報は、(singi = (1/0,...,1/0))
    for x,y in L[j]:
      #jさんの情報      
      #i[j] :sinngi　正解
      #y:sinngi　を変換
      if i[j]==0:
        y = ~y
      #x-1さんの正解i[j]
      if i[x-1]==y:
        flg = False
        break
  if flg:
    cnt = max(cnt,sum(i))
print(cnt)

Submission status: Wrong Answer

Solution code:
def is_contradiction2(tm, mask):
    N = len(mask)
    true_list = mask
    contradiction = False

    for i in range(N):
        for (xi, yi) in tm[i]:
            if (true_list[xi-1] != (yi if (true_list[i]) else not yi)):
                contradiction = True
                break

    return contradiction


N = int(input())

tm = [None] * N

for i in range(N):
    Ai = int(input())
    tmi = [None] * (Ai)
    for j in range(Ai):
        tmi[j] = list(map(int, input().split()))
    tm[i] = tmi


truthers = 0

for i in range(2**N-1, 0, -1):
    bitmask = list(map(int, format(i, "0{}b".format(N))))
    if (not is_contradiction2(tm, bitmask)):
        truthers = max(truthers, sum(bitmask))

print(truthers)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = []
for i in range(N):
  A = int(input())
  if A>0:
    for j in range(A):
      x, y= map(int,input().split())
      L.append([i+1,x,y])

from itertools import product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = 1
  for j in L:
    #jの情報は、(hatsugen=i,hito=x,flg=1,0)
    #iの情報は、(flg(i),...,)
    if i[j[0]-1]==1:k = j[2]
    else:k = 1 - j[2]
    if i[j[1]-1]!=k:
      flg = 0
      break
  if flg == 1:
    cnt = max(cnt,sum(i))
print(cnt)

Submission status: Wrong Answer

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

from itertools import permutations, combinations,combinations_with_replacement,product
LL = list(product(range(2), repeat=N))
cnt = 0
for i in LL:
  flg = 1
  for j in L:
    #jの情報は、(hatsugen=i,hito=x,flg=1,0)
    #iの情報は、(flg(i),...,)
    if i[j[0]-1]==1:
      k = j[2]
    else:
      k = 1- j[2]
    if i[j[1]-1]!=k:
      flg = 0
      break
  if flg == 1:
    cnt = max(cnt,sum(i))
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

result = 0
for i in range(1, 2 ** N):
    consistent = True
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        for x, y in s[j]:
            if (i >> j) & 1 != y:
                consistent = False
                break
        if not consistent:
            break
    if consistent:
        result = max(result, bin(i)[2:].count('1'))
print(result)

Submission status: Wrong Answer

Solution code:
import sys
bbn=1000000007
	
#+++++

def get_m(says, state, person):
	if person == len(state):
		return sum(state)
	
	if state[person] == 0:
		return get_m(says,state,person+1)
		
	if state[person]==1:
		sss=state[:]
		for x,y in says[person]:
			if sss[x] == -1:
				sss[x]=y
			elif sss[x] != y:
				#mujun
				return 0
			else:
				continue
			
		return get_m(says,state,person+1)
		
	
	sa=state[:]
	sa[person]=0
	a = get_m(says, sa, person+1)
	
	sb=state[:]
	sb[person]=1
	for x,y in says[person]:
		if sb[x] == -1:
			sb[x]=y
			
		elif sb[x] != y:
			#mujun
			return a
		else:
			continue
		
	b=get_m(says,sb,person+1)
	
	return max(a, b)
		
def main():
	n = int(input())
	says = [[] for _ in range(n)]
	for i in range(n):
		aij=int(input())
		for j in range(aij):
			x,y=map(int, input().split())
			says[i].append([x-1,y])
	a=[-1]*n
	
	ret=get_m(says, a,-1)
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
for i in range(N):
    A = int(input())
    xy.append([])
    
    for j in range(A):
        xy[i].append(tuple(map(int, input().split())))
 
ans = 0
 
for i in range(2 ** N):
    h = [0] * N
    
 
    for j in range(N):
        if (i >> j) & 1:
            h[j] = 1
    print(h)
    flag = False
    for i in range(N):
        if h[i] == 1:
            for x, y in xy[i]:
                if h[x-1] != y:
                    flag = True
                    break
            if flag:
                break
    
    if not flag:
        print(sum(h))
        ans = max(ans, sum(h))
 
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

n = int(input())
r = range(n)
a = [(set(), set()) for _ in r]
b = [(set(), set()) for _ in r]
for i in r:
  for _ in range(int(input())):
    x, y = map(int, input().split())
    a[i][y].add(x - 1)
    b[x - 1][y].add(i)


fail = lambda x: (not any(a[i][0].isdisjoint(x) and a[i][1] <= x for i in x)
                  or any(x & y and x & z for y, z in b))

while n and all(map(fail, map(set, combinations(r, n)))):
  n -= 1
print(n)