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:
from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)
from copy import deepcopy

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))
def R(x):
    r = round(x)
    if r+0.5 <= x:
        r += 1
    return r

def BFS(table, honest, next):
    p = next.pop(0)
    swt = 1
    for i in range(len(table[p])):
        q = table[p][i]
        if q!=-1:            
            if honest[i]!=-1:
                if q:
                    if q^honest[i]:
                        return False
                else:
                    if swt:
                        if not q^honest[i]:
                            honest[p] = 1
                        else:
                            honest[p] = 0
                            swt = 0

            else:
                if q:
                    next.append(i)
                honest[i] = q
    if 0<len(next):
        return BFS(table,honest,next)
    else:
        return True

n = I()
a = []
table = [[-1]*n for _ in range(n)]
for i in range(n):
    A = I()
    a.append(A)
    for _ in range(A):
        tmp = LI()
        table[i][tmp.pop()-1] = tmp.pop()

max = 0
ans = 0
for i in range(n):
    honest = [-1]*n
    honest[i] = 1
    if BFS(deepcopy(table),honest,[i]):
        x = honest.count(1)
        if max<x:
            max = x
            ans = max
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)
from copy import deepcopy

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))
def R(x):
    r = round(x)
    if r+0.5 <= x:
        r += 1
    return r

def BFS(table, honest, next):
    p = next.pop(0)
    for i in range(len(table[p])):
        q = table[p][i]
        if q!=-1:            
            if honest[i]!=-1:
                if q^honest[i]:
                    return False
            else:
                if q:
                    next.append(i)
                honest[i] = q
    if 0<len(next):
        return BFS(table,honest,next)
    else:
        return True

n = I()
a = []
table = [[-1]*n for _ in range(n)]
for i in range(n):
    A = I()
    a.append(A)
    for _ in range(A):
        tmp = LI()
        table[i][tmp.pop()-1] = tmp.pop()

max = 0
ans = 0
for i in range(n):
    honest = [-1]*n
    honest[i] = 1
    if BFS(deepcopy(table),honest,[i]):
        if max<honest.count(1):
            max = honest.count(1)
            ans = max
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


N = int(input())
XY = []
ANS = []


for _ in range(N):
    a = int(input())
    tmp = []

    for _ in range(a):
        xy = tuple(map(int, input().split()))
        tmp.append(xy)
    XY.append(tmp)


for b in range(2 ** N):
    status = []
    for i in range(N):
        j = b >> i & 1
        status.append(j)
    status = np.array(status)

    f = 1
    ans = 0

    for i in range(N):
        j = b >> i & 1
        for x, y in XY[i]:
            y = y == j
            s = status[x - 1]
            if s != y:
                f = 0
                break
        if not f:
            break

    if f:
        ans = np.sum(status)
    ANS.append(ans)


print(max(ANS))

Submission status: Wrong Answer

Solution code:
import numpy as np


N = int(input())
XY = []
ANS = []


for _ in range(N):
    a = int(input())
    tmp = []

    for _ in range(a):
        xy = tuple(map(int, input().split()))
        tmp.append(xy)
    XY.append(tmp)


for b in range(2 ** N):
    status = []
    for i in range(N):
        j = b >> i & 1
        status.append(j)
    status = np.array(status)

    f = 1
    ans = 0

    for i in range(N):
        j = b >> i & 1
        for x, y in XY[i]:
            s = status[x - 1]
            if s != y:
                f = 0
                break
        if not f:
            break

    if f:
        ans = np.sum(status)
    ANS.append(ans)

    f = 1
    ans = 0

    for i in range(N):
        j = b >> i & 1
        for x, y in XY[i]:
            y = y == j
            s = status[x - 1]
            if s != y:
                f = 0
                break
        if not f:
            break

    if f:
        ans = np.sum(status)
    ANS.append(ans)


print(max(ANS))

Submission status: Wrong Answer

Solution code:
import numpy as np


N = int(input())
XY = []
ANS = []


for _ in range(N):
    a = int(input())
    tmp = []

    for _ in range(a):
        xy = tuple(map(int, input().split()))
        tmp.append(xy)
    XY.append(tmp)


for b in range(2 ** N):
    status = []
    for i in range(N):
        j = b >> i & 1
        status.append(j)
    status = np.array(status)

    f = 1
    ans = 0

    for i in range(N):
        j = b >> i & 1
        for x, y in XY[i]:
            if j == 0:
                y = y == 0
            s = status[x - 1]
            if s != y:
                f = 0
                break
        if not f:
            break

    if f:
        ans = np.sum(status)
    ANS.append(ans)


print(max(ANS))

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)
from copy import deepcopy

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))
def R(x):
    r = round(x)
    if r+0.5 <= x:
        r += 1
    return r

def BFS(table, honest, next):
    p = next.pop(0)
    for i in range(len(table[p])):
        if table[p][i]!=-1:
            q = table[p][i]
            if not honest[p]:
                q = not q
            if honest[i]!=-1:
                if q^honest[i]:
                    return False
            else:
                next.append(i)
                honest[i] = q
    if 0<len(next):
        return BFS(table,honest,next)
    else:
        return True

n = I()
a = []
table = [[-1]*n for _ in range(n)]
for i in range(n):
    A = I()
    a.append(A)
    for _ in range(A):
        tmp = LI()
        table[i][tmp.pop()-1] = tmp.pop()

max = 0
ans = 0
for i in range(n):
    honest = [-1]*n
    honest[i] = 1
    if BFS(deepcopy(table),honest,[i]):
        if max<honest.count(1):
            max = honest.count(1)
            ans = max
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
setrecursionlimit(10**6)
from copy import deepcopy

def S(): return stdin.readline().rstrip()
def I(): return int(stdin.readline().rstrip())
def LS(): return list(stdin.readline().rstrip().split())
def LI(): return list(map(int,stdin.readline().rstrip().split()))
def R(x):
    r = round(x)
    if r+0.5 <= x:
        r += 1
    return r

def BFS(table, honest, next):
    p = next.pop(0)
    for i in range(len(table[p])):
        if table[p][i]!=-1:
            q = table[p][i]
            if not honest[p]:
                q = not q
            if honest[i]!=-1:
                if q^honest[i]:
                    return False
            else:
                next.append(i)
                honest[i] = q
    if 0<len(next):
        return BFS(table,honest,next)
    return True

n = I()
a = []
table = [[-1]*n for _ in range(n)]
for i in range(n):
    A = I()
    a.append(A)
    for _ in range(A):
        tmp = LI()
        table[i][tmp.pop()-1] = tmp.pop()

max = 0
ans = 0
for i in range(n):
    honest = [-1]*n
    honest[i] = 1
    if BFS(deepcopy(table),honest,[i]):
        if max<honest.count(1):
            max = honest.count(1)
            ans = max
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    z = [-1] * 10
    xy = []
    n = int(input())
    for _ in range(n):
        a = int(input())
        xy.append([list(map(int, input().split())) for _ in range(a)])
    ans = 0
    
    for a in range(2**n):
        c = []
        for b in range(n):
            c.append(a >> b & 1)
       
        flag = True
                        
        if flag:
            ans = max(ans, sum(c))
    
    print(ans)
        
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
    z = [-1] * 10
    xy = []
    n = int(input())
    for _ in range(n):
        a = int(input())
        xy.append([list(map(int, input().split())) for _ in range(a)])
    
    print(0)
        
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[[float('inf')]*n for i in range(n)]
ans=0
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=[int(s) for s in input().rstrip().split()]
    l[i][x-1]=y

for i in range(2**n):
  d=[0 for j in range(n)]
  for j in range(n):
    if i>>j & 1:
      d[j]=1
  minus=0
  for j in range(n):
    if d[j]==1:
      for k in range(n):
        if l[j][k]==float('inf'):
          continue
        if l[j][k]!=d[k]:
          minus+=1
  ans=max(ans,sum(d)-minus)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
x=[[] for i in range(n)]
y=[[] for i in range(n)]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    tmp = list(map(int,input().split()))
    x[i].append(tmp[0])
    y[i].append(tmp[1])

# 事実をbitで表現する
res=0
for bit in range(2**n):
  p_cnt = 0
  fact = 1
  for i in range(n): # 1人ずつ証言を検証する
    for j in range(a[i]):
      if (bit >> i & 1)^y[i][j] ==  (bit >> x[i][j] -1) & 1:
        break
    else:
      p_cnt += bit >> i & 1  # その人が真なら追加
  if fact and res < p_cnt:
    res = p_cnt
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
x=[[] for i in range(n)]
y=[[] for i in range(n)]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    tmp = list(map(int,input().split()))
    x[i].append(tmp[0])
    y[i].append(tmp[1])

# 事実をbitで表現する
res=0
for bit in range(2**n):
  p_cnt = 0
  fact = 1
  for i in range(n): # 1人ずつ証言を検証する
    p_cnt += bit >> i & 1  # その人が真なら追加
    for j in range(a[i]):
      if (bit >> i & 1)^y[i][j] ==  (bit >> x[i][j] -1) & 1:
        fact=0
  if fact and res < p_cnt:
    res = p_cnt
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math





n= int(input())



xandy=np.ones((n,n))

xandy=xandy*(-1)

flag=0
for i in range(0,n):
    a=int(input())
    for j in range(0,a):
        x,y= map(int, input().split())
        xandy[i][x-1]=y

max=0


for l in range(0,2**n):
    i=2**n-1-l
    flag=1
    for j in range(0,n):
       
       #iを2進数表示した時kの位置ででの0-1が対応してあるか立っているか？
        if  bin( i& 2**j).count("1")>0:
             for k in range(0,n):
                  if  xandy[j][k]!=-1 and xandy[j][k]!=(i >> k)%2:
                      flag=0 
                      break
                       
        if flag==0:
            break
    if flag==1 and max<bin(i).count("1"):
         max=bin(i).count("1")
         break

print(max)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math





n= int(input())



xandy=np.ones((n,n))

xandy=xandy*(-1)

flag=0
for i in range(0,n):
    a=int(input())
    for j in range(0,a):
        x,y= map(int, input().split())
        xandy[i][x-1]=y

max=0


for i in range(0,2**n):
    flag=1
    for j in range(0,n):
       
       #iを2進数表示した時kの位置ででの0-1が対応してあるか立っているか？
        if  bin( i& 2**j).count("1")>0:
             for k in range(0,n):
                  if  xandy[j][k]!=(i >> k)%2:
                      flag=0 

    if flag==1 and max<bin(i).count("1"):
         max=bin(i).count("1")

print(max)

Submission status: Wrong Answer

Solution code:
N = int(input())
aa = [0] * N * 2
#print(aa)

for i in range(N):
  chk = int(input())
  
  for ii in range(chk):
      num, ans = map(int,input().split())
      #print(num, ans)
      aa[num] = aa[num] * ans

print(sum(aa))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
x = []
y = []
for i in range(N):
    x_ = []
    y_ = []
    A[i] = int(input())
    for _ in range(A[i]):
        in1, in2 = list(map(int,input().split()))
        x_.append(in1 - 1)
        y_.append(in2)
    x.append(x_)
    y.append(y_)

def bit_all():
    ret = 0
    for p in range(2 ** N):
        temp = 0
        flag = 1
        b = str(format(p, '020b'))
        for i in range(N):
            if b[-(i + 1)] == "1":
                for j in range(A[i]):
                    # 矛盾
                    if int(b[-(x[i][j] + 1)]) != y[i][j]:
                        flag = 0
                temp += 1
            else:
                for j in range(A[i]):
                    # 矛盾
                    if int(b[-(x[i][j] + 1)]) == y[i][j]:
                        flag = 0
        if flag:
            ret = max(ret, temp)
    return ret

ans = bit_all()
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
x = []
y = []
for i in range(N):
    x_ = []
    y_ = []
    A[i] = int(input())
    for i in range(A[i]):
        in1, in2 = list(map(int,input().split()))
        x_.append(in1 - 1)
        y_.append(in2)
    x.append(x_)
    y.append(y_)

def bit_all():
    ret = 0
    for p in range(2 ** N):
        temp = 0
        flag = 1
        b = str(format(p, '015b'))
        for i in range(N):
            if b[-(i + 1)] == "1":
                for j in range(A[i]):
                    # 矛盾
                    if int(b[-(x[i][j] + 1)]) != y[i][j]:
                        flag = 0
                temp += 1
            else:
                for j in range(A[i]):
                    # 矛盾
                    if int(b[-(x[i][j] + 1)]) == y[i][j]:
                        flag = 0
        if flag:
            ret = max(ret, temp)
    return ret

ans = bit_all()
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
XY = [[] for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    XY[i].append(input())
for i in range(2**N):
  for j in range(N):
    if (i >> j) & 1:
      for xy in XY[j]:
        x, y = map(int, xy.split())
        x -= 1
        if (i >> x) & 1 != y:
          break
      else:
        continue
      break
    else:
      for xy in XY[j]:
        x, y = map(int, xy.split())
        x -= 1
        if (i >> x) & 1 == y:
          break
      else:
        continue
      break
  else:
    ans = max(ans, sum((i >> k) & 1 for k in range(N)))
    continue
print(ans)

Submission status: Wrong Answer

Solution code:
if 0:
  print(0)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
shoujiki=[[] for i in range(n)]
usotsuki=[[] for i in range(n)]
for i in range(n):
	a = int(input())
	for j in range(a):
		x,y = map(int,input().split())
		if y == 0:
			usotsuki[i].append(x-1)
		else:
			shoujiki[i].append(x-1)
ans = 0
for i in range(2**n):
	sl = []
	t = 0
	for j in range(n):
		if (i>>j) & 1:
			sl.append(1)
			t += 1
		else:
			sl.append(0)
	yes = 1
	for j in range(n):
		mode = 0
		if sl[j] == 0:
			mode = 1
		for k in shoujiki[j]:
			if sl[k] == mode:
				yes = 0
				break
		if yes == 0:
			break
		for k in usotsuki[j]:
			if sl[k] == 1-mode:
				yes = 0
				break
		if yes == 0:
			break
	if yes == 1:
		ans = max(t, ans)
print(ans)

Submission status: Wrong Answer

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

res = 0
for i in range(1<<N):
  mapper = {1: [], 0: []}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:

      for x,y in conditions[j]:
        if y==1 and not (i>>x)&1:
          flg = False
          break
        elif y==0 and (i>>x)&1:
          flg = False
          break
        cnt += 1

    if not flg: break

  if flg:
    res = max(res, cnt)

print(res)

Submission status: Wrong Answer

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

res = 0
for i in range(1<<N):
  mapper = {1: set(), 0: set()}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:
      if j in mapper[0]:
        flg = False
        break
      for x,y in conditions[j]:
        if x in mapper[1-y]:
          flg = False
          break
        mapper[y].add(x)
      cnt += 1
    if not flg: break

  # print(i, mapper)
  if flg:
    res = max(res, cnt)

print(res)

Submission status: Wrong Answer

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

res = 0
for i in range(1<<N):
  mapper = {1: [], 0: []}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:
      for x,y in conditions[j]:
        if x in mapper[1-y] or j in mapper[0]:
          flg = False
          break
        mapper[y].append(x)
      cnt += 1
    else:
      for x,y in conditions[j]:
        if x in mapper[y]:
          flg = False
          break
        mapper[1-y].append(x)

    if not flg:
      break


  if flg:
    res = max(res, cnt)

print(res)

Submission status: Wrong Answer

Solution code:

def main1():
    n = int(input())
    lis = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            lis[i].append(list(map(int, input().split())))
    res = 0

    for i in range(1<<n):
        syouziki = []
        uso=[]
        f = True
        tmp=0
        for j in range(n):
            if(i&1<<j):
                syouziki.append(j)
                for k in lis[j]:
                    if k[1]==1:
                        syouziki.append(k[0]-1)
                    else:
                        uso.append(k[0]-1)
        for j in syouziki:
            for k in lis[j]:
                if k[1]==1 and k[0]-1 in uso:
                    f=False
                if k[0]==0 and k[1]-1 in syouziki:
                    f=False

        if len(set(uso)&set(syouziki))>0:
            f=False


        #print(uso,syouziki, bin(i), len(set(uso)&set(syouziki)),f)

        if f:
            res = max(res, len(set(syouziki)))

    print(res)






if __name__ == '__main__':
    main1()

Submission status: Wrong Answer

Solution code:
import itertools
from collections import Counter
n = int(input())

'''
変数名ループ
exec('name%02d = %03d' % (n,K*100))
'''
data = [0] * n
for i in range(n):
    a = int(input())
    data[i] = [list(map(int, input().split())) for _ in range(a)]

# print(data)
ans = 0
for i in itertools.product([1, 0], repeat=n):
    flag = True
    # print(i)
    for j, val in enumerate(data):
        #val2 = val[0]
        if (i[j] == 0):  # 嘘つき
            tt = -1
        else:
            tt = 0

        # valはJ人目の回答list
        for k, tar in enumerate(val):
            #print('j, val', j, val)
            #print('k, tar', k, tar)
            who = tar[0] - 1
            which = tar[1]

            if (tt == -1 and which == 1):
                which = 0
            if (tt == -1 and which == 0):
                which = 1

            #print(who, which)
            if (which == i[who]):
                # print('OK')
                pass
            else:
                flag = False
                # print('NG')
                break
        # --------------------
        if (flag is False):
            break
    # print(flag)
    if (flag is True):
        count = Counter(i)
        # print(count)
        ans = max(count[1], ans)

    else:
        continue


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
xy = [[]  for _ in range(n)]
ans = 0

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

for j in range(2 ** n):
    flag = 1
    count = []
    for k in range(n):
        if j >> k & 1 == 1:
            count.append(k)
            for x, y in xy[k]:
                if y == 0 and x in count:
                    flag = 0
                if y == 1 and x not in count:
                    flag = 0
        ans = max(ans, flag * len(count))

print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**n):  # うそほんとパターン
    h = 0
    for j in range(n):
        if ((i >> j) & 1):
            h += 1
    flag = 1
    for j in range(n):  # 各人のパターン
        if ((i >> j) & 1):  # しょうじき
            for x,y in xy[j]:
                if y == 1 and not ((i >> (x-1)) & 1):
                    flag = 0
                    break
                elif y == 0 and ((i >> (x-1)) & 1):
                    flag = 0
                    break
        else:  #うそつき
            for x,y in xy[j]:
                if y == 1 and ((i >> (x-1)) & 1):
                    flag = 0
                    break
                elif y == 0 and not ((i >> (x-1)) & 1):
                    flag = 0
                    break
    if flag:
        ans = max(ans,h)
    #print(bin(i),ans)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**n):  # うそほんとパターン
    h = str(bin(i)).count('1')
    flag = 1
    for j in range(n):  # 各人のパターン
        if ((i >> j) & 1):  # しょうじき
            for x,y in xy[j]:
                if y == 1 and not ((i >> (x-1)) & 1):
                    flag = 0
                    #break
                elif y == 0 and ((i >> (x-1)) & 1):
                    flag = 0
                    #break
        else:  #うそつき
            for x,y in xy[j]:
                if y == 1 and ((i >> (x-1)) & 1):
                    flag = 0
                    #break
                elif y == 0 and not ((i >> (x-1)) & 1):
                    flag = 0
                    #break
    if flag:
        ans = max(ans,h)
    #print(bin(i),ans)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(2**n):  # うそほんとパターン
    h = str(bin(i)).count('1')
    flag = 1
    for j in range(n):  # 各人のパターン
        if ((i >> j) & 1):  # しょうじき
            for x,y in xy[j]:
                if y == 1 and not ((i >> (x-1)) & 1):
                    flag = 0
                    break
                elif y == 0 and ((i >> (x-1)) & 1):
                    flag = 0
                    break
        else:  #うそつき
            for x,y in xy[j]:
                if y == 1 and ((i >> (x-1)) & 1):
                    flag = 0
                    break
                elif y == 0 and not ((i >> (x-1)) & 1):
                    flag = 0
                    break
    if flag:
        ans = max(ans,h)
print(ans)

Submission status: Wrong Answer

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

ans = 0
for i in range(1 << N):
    hornest = [0] * N
    for j in range(N):
        if (i << j)&1:
            hornest[j] = 1
    is_ok = 1
    for j in range(N):
        if hornest[j]:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hornest[k]:
                    is_ok = 0
    if is_ok:
        ans = max(ans,hornest.count(1))
        
print(ans)

Submission status: Wrong Answer

Solution code:
def list_and(array1,array2):
    result = []
    for i,j in zip(array1,array2):
        if i and j:
            result.append(1)
        else:
            result.append(0)
    return result


def result_list(array1,array2):
    result = []
    flag = 1
    for i,j in zip(array1, array2):
        if i != j:
            flag = 0
    return flag


N = int(input())
honest = []
for i in range(N):
    n = int(input())
    s = [1 for _ in range(N)]
    for _ in range(n):
        h, horu = map(int,input().split())
        s[h-1] = horu
    honest.append(s)
    
cnt = 0
for i in range(i << N):
    if i == 0:
        continue

    hh = [0] * N
    b = [1] * N
    in_cnt = 0
    for j in range(N):
        if (i >> j)&1:
            hh[j] = 1
            in_cnt += 1
    for k,v in enumerate(hh):
        if v == 1:
            b = list_and(b,honest[k])
    if result_list(b,hh):
        cnt = max(cnt,in_cnt)
        
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())

'''
変数名ループ
exec('name%02d = %03d' % (n,K*100))
'''
data = [0] * (n - 1)
for i in range(n-1):
    a = int(input())
    data[i] = [list(map(int, input().split())) for _ in range(a)]
    #print(data, 'aa')

ans = 0
for i in itertools.product([1, 0], repeat=n):
    flag = True
    for j, val in enumerate(data):
        #num = len(val)
        #print(val)
        num = len(val)
        for k in range(num):
            tar = val[k]
            who = tar[0] - 1
            which = tar[1]
            if (which == i[who]):
                pass
            else:
                flag = False
                break
        if (flag is False):
            break

    if (flag is True):
        ans += 1
    else:
        continue


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [None]*n
for i in range(n):
  m=int(input())
  a[i] = [list(map(int, input().split())) for _ in [0]*m]

ans = 0
for i in range(2**n):
  done = [-1]*n
  for j in range(n):
    if(i>>j)&1==0:
      if done[j] == 1: break
      done[j] == 0
      continue
    if done[j] == 0: break
    done[j] = 1
    breakFlg = False
    for x,y in a[j]:
      x-=1
      if done[x] == -1:
        done[x] = y
      elif done[x] !=y:
        breakFlg = True
        break
    if breakFlg: break
  else:
    tmp = sum(map(int, bin(i)[2:]))
    ans = max(ans,tmp)
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
xy =[[]for i in range(N)]
ans=0

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


for i in range(2**N):
    ans_kouho=0
    #発言に矛盾があればflag=-1,矛盾がなければflag=1
    flag=1
    #Torf[i]=1ならi+1人目は正直者、0なら嘘つき
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==0:#発言者が嘘つきならば
                if TorF[xy[j][k][0]-1]==xy[j][k][1]:
                    flag=-1
                    break
            else:#発言者が正直者ならば
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    flag=-1
                    break
    
    if flag==1:
        
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
xy =[[]for i in range(N)]
ans=0

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


for i in range(2**N):
    ans_kouho=0
    #発言に矛盾があればflag=-1,矛盾がなければflag=1
    flag=1
    #Torf[i]=1ならi+1人目は正直者、0なら嘘つき
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==0:#発言者が嘘つきならば
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    continue
                else:
                    flag=-1
                    break
            else:#発言者が正直者ならば
                if TorF[xy[j][k][0]-1]==xy[j][k][1]:
                    continue
                else:
                    flag=-1
                    break
    
    if flag==1:
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
xy =[[]for i in range(N)]
ans=0

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


for i in range(2**N):
    ans_kouho=0
    #発言に矛盾があればflag=-1,矛盾がなければflag=1
    flag=1
    #Torf[i]=1ならi+1人目は正直者、0なら嘘つき
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==0:#発言者が嘘つきならば
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    continue
                else:
                    flag=-1
            else:#発言者が正直者ならば
                if TorF[xy[j][k][0]-1]==xy[j][k][1]:
                    continue
                else:
                    flag=-1
    
    if flag==1:
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)

Submission status: Wrong Answer

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

c_max = 0
cnt = 0
for i in range(1 << N):
    ok = True
    for j in range(N):
        if (i >> j) & 1:
            continue
        for x, y in (xy[j]):
            if (i >> x) & 1 != y:
                ok = False
                break
        if not ok:
            break

    if ok:
        cnt = bin(i)[2:].count('1')
        if cnt > c_max:
            c_max = cnt

print(c_max)