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: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

int g[15][15];

int main() {
  int n;
  cin >> n;
  rep(i,n)rep(j,n) g[i][j] = -1;
  rep(i,n) {
    int m;
    cin>>m;
    rep(j,m){
      int a, x;
      cin>>a>>x;
      --a;
      g[i][a] =x;
    }
  }
  int ans = 0;
  rep(i,1<<n) {
    vector<int> d(n);
    rep(j,n) if (i>>j&1) {
      d[j] = 1;
    }
    bool ok = true;
    rep(j,n) {
      if(d[j]) {
        rep(k,n) {
          if (g[j][k] == -1) continue;
          if (g[j][k] != d[k]) ok = false;
        }
      }
    }
    if (ok) ans = max(ans, __builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
testimony = [[] for _ in range(n)]
people = [-1 for _ in range(n)]
ans = 0
for i in range(n):
    k = input()
    sss = list(map(int, input().split()))
    testimony[i] = sss
for i in range(1, (1<<n)+1):
    for j in range(n):
        if i>>n&1:
            if people[testimony[j][0]-1] == -1:
                people[testimony[j][0]-1] = testimony[j][1]
            elif people[testimony[j][0]-1] == testimony[j][1]:
                pass
            else:
                continue
    tmp = bin(i).count('1')
    ans = max(tmp, ans)
print(ans)

Submission status: Runtime Error

Solution code:
#C
n = int(input())
a = []
testimony = [-1]*n
ans = 0
for i in range(n):
    a.append(int(input()))#証言の個数
    l = []
    for j in range(a[i]):
        l.append(list(map(int, input().split())))
    if l != []:
        testimony[i] = l#iの人のa[i]個の証言のリスト
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1 and a[n-1-j] != -1:
            for k in range(a[n-1-j]):
                if ((i >> (n - testimony[n-1-j][k][0])) & 1) = testimony[n-1-j][k][1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, str(bin(i)).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
x = []
y = []
words = []
for i in range(N):
  A = int(input())
  W = []
  for _ in range(A):
    x, y = map(int, input().split())
    W.append([x-1, y])
  words.append(W)
  
ans = 0
for bit in range(1<<n):
  ok = True
  is_honest = [(bit>>i) & 1 for i in range(N)]
  for i in range(N):
    if not is_honest[i]:
      continue
    for x, y in words[i]:
      if is_honest[x] != y:
        ok = False
  if ok:
    ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
xy=[[] for i in range(n)]
ans=0
a=[0]*n
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x,y=map(int,input().split())
    xy[i].append([x,y])
for i in range(2**n):
  temp=[0]*n
  for j in range(n):
    if ((i >> j) & 1):
      temp[j]=1
  count=True
  for j in range(n):
    for k in range(a[j]):
      if temp[j]==1:
        p=xy[j][k][0]
        if temp[p]!=xy[j][k][0]:
          count=False
      else:
        p=xy[j][k][0]
        if temp[p]==xy[j][k][0]:
          count=False     
  if count==True:
    ans=max(ans,sum(temp))
print(ans)

Submission status: Runtime Error

Solution code:
#C
n = int(input())
a = []
testimony = []
ans = 0
for i in range(n):
    a.append(int(input()))#証言の個数
    l = []
    if a[i] == 0:
        l.append([])
        continue
    for j in range(a[i]):
        l.append(list(map(int, input().split())))
    testimony.append(l)#iの人のa[i]個の証言のリスト
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1 and a[n-1-j] != 0:
            for k in range(a[n-1-j]):
                if (i >> (n - testimony[n-1-j][k][0])) != testimony[n-1-j][k][1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, str(bin(i)).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
#C
n = int(input())
a = []
testimony = []
ans = 0
for i in range(n):
    a.append(int(input()))#証言の個数
    l = []
    if a[i] == 0:
        l.append(-1)
    for j in range(a[i]):
        l.append(list(map(int, input().split())))
    testimony.append(l)#iの人のa[i]個の証言のリスト
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1 and testimony[n-1-j][k] != -1:
            for k in range(a[n-1-j]):
                if (i >> (n - testimony[n-1-j][k][0])) != testimony[n-1-j][k][1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, str(bin(i)).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
#C
n = int(input())
a = []
testimony = []
ans = 0
for i in range(n):
    a.append(int(input()))#証言の個数
    l = []
    if a[i] == 0:
        l.append([0,0])
        continue
    for j in range(a[i]):
        l.append(list(map(int, input().split())))
    testimony.append(l)#iの人のa[i]個の証言のリスト
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            for k in range(a[n-1-j]):
                if (i >> (n - testimony[n-1-j][k][0])) != testimony[n-1-j][k][1]:
                    break
            else:
                continue
            break
    else:
        ans = max(ans, str(bin(i)).count('1'))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = []
insist = []
for _ in range(N):
    n = int(input())
    A.append(n)
    lis = []
    for i in range(n):
        lis.append(list(map(int, input().split())))
    insist.append(lis)

ans = 0
def dfs(i, s):
    global ans
    if i == N:
        judge = True
        for i in range(len(s)):
            for j in range(A[i]):
                if (insist[i][j][1] == 1) and (str(insist[i][j][0]-1) not in s):
                    judge = False
                elif (insist[i][j][1] == 0) and (str(insist[i][j][0]-1) in s):
                    judge = False
        if judge:
            ans = max(ans, len(s))
            return
        else:
            return
    dfs(i + 1, s)
    dfs(i + 1, s + str(i))

dfs(0, '')
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = []
insist = []
for _ in range(N):
    n = int(input())
    A.append(n)
    lis = []
    for i in range(n):
        lis.append(list(map(int, input().split())))
    insist.append(lis)

ans = 0
def dfs(i, s):
    global ans
    if i == N:
        judge = True
        for i in range(len(s)):
            for j in range(A[i]):
                if (insist[i][j][1] == 1) and (str(insist[i][j][0]-1) not in s):
                    judge = False
                elif (insist[i][j][1] == 0) and (str(insist[i][j][0]-1) in s):
                    judge = False
        if judge:
            ans = max(ans, len(s))
            return
        else:
            return
    dfs(i + 1, s)
    dfs(i + 1, s + str(i))

dfs(0, '')
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
A = []
insist = []
for _ in range(N):
    n = int(input())
    A.append(n)
    lis = []
    for i in range(n):
        lis.append(list(map(int, input().split())))
    insist.append(lis)

ans = 0
def dfs(i, s):
    global ans
    if i == N:
        test = ''
        for i in range(len(s)):
            for j in range(A[i]):
                if insist[i][j][1] == 1:
                    test += str(insist[i][j][0]-1)
        if set(test) == set(s):
            ans = max(ans, len(s))
            return
        else:
            return
            
    dfs(i + 1, s)
    dfs(i + 1, s + str(i))

dfs(0, '')
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)

N = int(input())
A = []
insist = []
for _ in range(N):
    n = int(input())
    A.append(n)
    lis = []
    for i in range(n):
        lis.append(list(map(int, input().split())))
    insist.append(lis)

ans = 0
def dfs(i, s):
    global ans
    if i == N:
        test = ''
        for i in range(len(s)):
            for j in range(A[i]):
                if insist[i][j][1] == 1:
                    test += str(insist[i][j][0]-1)
        if set(test) == set(s):
            ans = max(ans, len(s))
            return
        else:
            return
            
    dfs(i + 1, s)
    dfs(i + 1, s + str(i))

dfs(0, '')
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
insist = []
for _ in range(N):
    n = int(input())
    A.append(n)
    lis = []
    for i in range(n):
        lis.append(list(map(int, input().split())))
    insist.append(lis)

ans = 0
def dfs(i, s):
    global ans
    if i == N:
        test = ''
        for i in range(len(s)):
            for j in range(A[i]):
                if insist[i][j][1] == 1:
                    test += str(insist[i][j][0]-1)
        if set(test) == set(s):
            ans = max(ans, len(s))
            return
        else:
            return
            
    dfs(i + 1, s)
    dfs(i + 1, s + str(i))

dfs(0, '')
print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
from queue import Queue
import heapq
import numpy as np

MOD = 5000000007

#n = int(input())
#s = int(input())
#a, b, c, x, y = [int(i) for i in input().split()]
#table = [[int(i)  for i in input().split()] for j in range(m)]
#table = [list(input()) for n in range(r)] #table[h][w]
#p = [int(i) for i in input().split()]
#s = [int(i) for i in range(n)]
#p = [int(input()) for i in range(m)]
#s = input()

#list = list(s)
#a = [0 for _ in range(n+1)]
#dp = [[0 for _ in range(n+1)] for _ in range(n+1)]

n = int(input())
word_list = [[] for i 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()]
        word_list[i].append((x-1,y))

ans = 0

for i in range(2**n):
    peoples = []
    flag = 1
    for j in range(n):
        if(i >> j & 1):
            peoples.append(1)
        else:
            peoples.append(0)
    
    for k in range(n):
        if peoples[k] == 1
            words = words_list[k]
            for word in words:
                if peoples[word[0]] != word[1]:
                    flag = 0
                    break
    
    if flag:
        ans = max(ans,sum(peoples))

print(ans)

Submission status: Runtime Error

Solution code:
2
1
2 0
1
1 n = int(input())

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

ans = 0
def judge(f):
    for i in range(n):
        if flag[i] == 1:
            for j in xy[i]:
                if f[j[0] - 1] != j[1]:
                    return False
        
    return True

for i in range(2 ** n):
    flag = [0] * n
    for j in range(n):
        if i >> j & 1:
            flag[j] = 1
    if judge(flag):
        ans = max(ans, sum(flag))
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
l=[]
for i in range(n):
  d=int(input())
  x,y=map(int,input().split())
  l.append([i,x-1,y])
out=0
for p in itertools.product([0,1],repeat=n):
  for ll in l:
    if p[ll[0]]==1 and p[ll[1]]!=ll[2]:
      out+=1
      break
print(n-out)

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
ans = 0
for i in range(n):
    x =int(input())
    lists = [list(map(int,input().split())) for j in range(x)]
    A.append(lists)

for i in range(2**n):
    honesty = [0]*n
    for j in range(n):
        if (i>>j) & 1:
            honesty[j] = 1
    true = 1
    for j in range(n):
        if honesty[j] == 1:
            for k in range(len(A[j])):
                x,y = A[j][k]
                
                if  honesty[x] != y :
                    true = 0
                    break
    if true == 1:
        ans = max(ans,sum(honesty))
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n = int(input())
a = [0] * n
xy = []
for i in range(n):
    a[i] = int(input())
    x_y = []
    for j in range(a[i]):
        x_y.append(list(map(int,input().split())))
    xy.append(x_y)

ans = 0
for it in itertools.product([0,1],repeat=n):
    li = [0] * n
    for i in range(len(a)):
        for k in range(n):
            for j in range(a[i]):
                if it[k] == 1:
                    if xy[k][j][1]==0:
                        li[xy[k][j][0]-1] = -1
                    else:
                        li[xy[k][j][0]-1] = 1
    flg = True                        
    for l in range(n):
        if li[l] == -1 and it[l] == 1 or li[l] == 1 and it[l] == -1 or li[l] == 1 and it[l] == 0:
            flg = False
    if flg:

        if ans < sum(it):
            ans = sum(it)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
n=int(input())
la=[]
for _ in range(n):
  d=int(input())
  for dd in d:
    x,y=map(int,input().split())
    la.append([_,x-1,y])
ans=0
for i in itertools.product([0,1],repeat=n):
  s=sum(list(i))
  for l in la:
    if i[l[0]]==1 and i[l[1]]!=l[2]:
      break
  else:
    ans=max(ans,s)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
la=[]
for i in range(n):
  d=int(input())
  a=[list(map(int,input().split())) for dd in range(d)]
  la.append(a)
cnt=n
for r in range(n-1):
  for p in range(r+1,n):
    for aa in la[r]
      for bb in la[p]:
        if aa[0]==bb[0] and aa[1]!=bb[1]:
          cnt-=1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=[]
x=np.full((n, n), -1)
p=[]
pp=[[0]*n for i in range(2**n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
      X,Y=(map(int,input().split()))
      x[i][X-1]=Y

def rev(x):
    if x ==1:
        return 0
    else:
        return 1
        
def dec2bin(target):
    amari=[]
    while target !=0:
        amari.append(target % 2)
        target = target //2
    if len(amari)!=n:
        while len(amari)!=n:
            amari.append(0)
    amari.reverse()
    return amari

for i in range(2**n):
    p.append(dec2bin(i))
b=[]
for i in range(2**n):
  flag=True
  for j in range(n):
      if p[i][j]==1:
        for k in range(n):
          if( x[j][k]==1 and p[i][k]==0)or (x[j][k]==0 and p[i][k]==1):
            flag=False
            break
    if flag==False:
      break
  if flag==True:
    b.append(p[i].count(1))
    
            
"""
                elif x[k][1]==0:
                    pp[i][x[k][0]-1]=0
                    
        elif p[i][j]==0:   
            for k in range(a[j]):
                if x[k][1]==0:
                    pp[i][x[k][0]-1]=1
                else:
                    pp[i][x[k][0]-1]=0
"""

if len(b)==0:
  print(0)
else:
  print(max(b))

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
P = []
ans = 0

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

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        if YN(k[0]) != k[1]:
          s = 0
          break
  ans = max(ans, s)

print(ans)

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
P = []
ans = 0

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

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        YN(k[0]) != k[1]
        s = 0
        break
  ans = max(ans, s)

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())

from collections import defaultdict
d = defaultdict(list)

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = [int(x) for x in input().split()]
        d[i].append((x - 1, y))
ans = 0
for k in range(2**n):
    res = 0
    j = bin(k)[2:].zfill(n)
    for i in range(n):
        if j[i] == "0":
            continue
        flag = 1
        for x, y in d[i]:
            if int(j[x]) != int(y):
                flag = 0
                break
        res += 1
    if flag:
        ans = max(ans, res)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
l = []
ans = 0
for i in range(N):
    A = int(input())
    for j in range(A):
        l.append(list(map(int,input().split())))
for bit in range(1<<N):
    flag = True
    listH = [(bit>>i)&1 for i in range(N)]
    for i in range(N):
        if not listH[i]:
            continue
        for k in range(2):
            x = l[i][0]-1
            y = l[i][1]
            if listH[x] != y:
                flag = False
    if flag:
        ans = max(ans,sum(listH))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
X = []
for i in range(n):
    a = int(input())
    A.append(a)
    lis = []
    for j in range(a):
        lis.append(list(map(int, input().split())))
    X.append(lis)

ans = 0
for i in range(2 ** n):
    H_lis = [0 for i in range(n)]
    for j in range(n):
        if ((i >> j) & 1):
            H_lis[j] = 1
    flag = True
    j = 0
    while j < n and flag:
        if H_lis[j] == 1:
            for k in range(A[k]):
                if X[j][k][1] != H_lis[X[j][k][0] - 1]:
                    flag = False
                    break
        j += 1
    if flag:
        ans = max(ans, H_lis.count(1))
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    ans = []
    for _ in range(n):
        a_num = int(input())
        t = []
        for _ in range(a_num):
            t.append(tuple(map(int, input().split())))
        t = tuple(t)
        ans.append(t)
   
    r = 0
    for bit in range(1 << n):
        honest = []
        for i1 in range(n):
            mask = 1<<i1
            if bit & mask:
                honest.append(i1)

        flag = 1
        if not honest:
            flag = 0
        for eh in honest:
            say = ans[eh]
            for esay in say:
                if esay[0] - 1 in honest:
                    if esay[1] == 0:
                        flag = 0
                else:
                    if esay[1]:
                        flag = 0
        if flag:
            r = max(r, len(honest))
    print(r)

if __name__ == '__main__':
    main(

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from itertools import*
n = int(input())
c = 0
z = [eval("[i] + list(map(int, input().split())),"*int(input())) for i in range(n)]
for j in product([0,1], repeat=n):
    if all(j[i] == 0 or j[x-1] - y == 0 for i, x, y in chain.from_iterable(z)):
        c = max(c, sum(j))
print(c)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env pypy3
import collections
import itertools as it
import math
#import numpy as np
 
n  = int(input())
#  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))i
xy = []
for _ in range(n):
    a = int(input())
    xy.append([tuple(map(int, input().split())) for _ in range(a)])
#
# c = collections.Counter()

for i in range(2 ** n): # 嘘つき・正直者の総当り
    is_honest = [not(bool(int(s))) for s in list(f'{i:015b}'[-n:])]
    is_ok = True
    for i, h in enumerate(list(is_honest)): # 人の総当り
        for x, y in xy[i]: # 証言の総当り
            if is_honest[i] == False:
                continue

            x = x - 1
            v = bool(int(y))
            
            #print(is_honest[x], bool(y), v, )
            if is_honest[x] == v:
                pass
            else:
                is_ok = False
    
    if is_ok:
        i#print(is_honest)
        print(sum(is_honest))
        break

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[] for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i].append((x-1,y))

cnt = 0
for i in range(2**N):
    flag = True
    for j in range(N):
        if (i>>j)&1 == 1:
            for x,y in tes[j]:
                if (i>>x)&1 != y:
                    flag = False
                    break
    if flag:
        cnt = max(cnt,bin(i)[2:].count(1))
print(cnt)

Submission status: Runtime Error

Solution code:
n=int(input())
ans=0

for i in range(2**n):
    m=bin(i)[2:].rjust(n, "0")
    cnt=0
    flag=0
    for j in range(n):
        A=int(input())
        if m[j]=="0":
            for k in range(A):
                b, c =input().split()

        elif m[j]=="1":
            for k in range(A):
                b ,c =input().split()
                b=int(b)
                if m[b-1]!=int(c):
                    flag=1
                elif m[b-1]==int(c) and c=="1":
                    cnt+=1
    
    if flag==0 and cnt>ans:
        ans=cnt

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    d = defaultdict(list)
    for i in range(N):
        n = int(input())
        for _ in range(n):
            d[i].append(list(map(int, input().split())))
    max_trust_num = 0

    # check all possible combinations of Honest or Unkind.
    for i in range(2**N):
        trust = True

        # assign Honest or Unnkind to each person.
        # if person i is Honest, trust_combs[i] = 1
        # else, trust_combs[i] = 0
        trust_combs = []
        for j in range(N):
            if (i >> j) & 1:
                trust_combs.append(1)
            else:
                trust_combs.append(0)
  
        # check if the combination of Honest or
        # Unkind contradicts the given statements.
        for k in range(len(trust_combs)):
            if trust_combs[k] == 1:
                for l in d[k]:
                    if not l[1] == trust_combs[l[0]-1]:
                        trust = False
        if trust:
            max_trust_num = max(max_trust_num, sum(trust_combs))

    print(max_trust_num)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
L=[[] for i in range(N)]
for i in range(N):
  M=int(input())
  L[i]=[list(map(int,input().split())) for j in range(M)]
#print(L)

L_2=[[i,None] for i in range(N)]
L_3=[0 for i in range(N)]
ans=0
for k in range(2**N):
	L_3=[0 for i in range(N)]
    Y_N=True
	count=0
	for a in range(N):
		if ((k >> a) & 1):  # 正直者のリストを作る
			L_3[a]=1
	for a in range(N):  # このループが一番のポイント
		if ((k >> a) & 1):  # 正直者のリスト
			count += 1
			for b in range(len(L[a])):
				if L_3[a] == 0: #もし正直者じゃないとされてたら
					Y_N=False #破綻
				person = L[a][b][0]-1
				if L_3[person]==1-L[a][b][1]: #すでに言われてることと矛盾
					Y_N=False #破綻
				L_3[person]=L[a][b][1] #証言の内容で人となりをアップデート
				#print(L_3,a,b)
	#print(L_3,count,Y_N)
	if Y_N:
		ans = max(ans, count)
print(ans)

Submission status: Runtime Error

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


ans = 0
for bit in range(1<<n):　#2のn乗まで捜査
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(n)]
	#bitをiずらして末尾が1のひとは正直
	for i in range(n):
		if not is_honest[i]:
			continue
		for x, y in words[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
words = []
for i in range(n):
	a = int(input())
	w = []
	for _ in range(a):
		x, y = map(int, input().split())
		w.append([x-1, y])
	words.append(w)


ans = 0
for bit in range(1<<n):　#2のn乗まで捜査
	ok = True
	is_honest = [(bit>>i) & 1 for i in range(n)]
	#bitをiずらして末尾が1のひとは正直
	for i in range(n):
		if not is_honest[i]:
			continue
		for x, y in words[i]:
			if is_honest[x] != y:
				ok = False
	if ok:
		ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
g=[[-1]*(N) for i in range(N)]#g[i][j]はi番目からのj番目に対する証言

for i in range(N):
    a=int(input())
    A.append(a)
    for j in range(a):
        x,y=map(int,input().split())
        x-=1
        g[i][x]=y
num=[]
for i in range(2 **N):
  chars = list(f"{i:0{N}b}")
  chars=list(map(int,chars))
  num.append(chars)


ans=[]
for x in num:
    ok = True
    for k in range(N):#k番目の人
        if x[k]:
            for j in range(N):
                if g[k][j]==-1:
                    continue
                elif g[k][j]!=x[j]:
                    ok=False
    if ok:
        ans.append(x.count(1))
print(max(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
testimony = [[] for _ in range(n)]

for i in range(n):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1], state)

honest = 0
for i in range(1, 2**n):
    flag = 0
    for j in range(n):
        if (i>>j)&1 == 1:
            for x, y in testimony[j]:
                if (i>>x)&1 != y:
                    flag = 1
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))

print(honest)

Submission status: Runtime Error

Solution code:
n = int(input())
testimony = [[] for _ in range(n)]

for i in range(n):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1], state)

honest = 0
for i in range(1, 2**n):
    flag = 0
    for j in range(n):
        if (i>>j)&1 == 1:
            for x, y in testimony[j]:
                if (i>>x)&1 != y:
                    flag = 1
                    break
    if flag == 0:
        honest = max(honest, bin(i)[2:].count('1'))

print(honest)

Submission status: Runtime Error

Solution code:
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

xy_arr = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = int(map(int, input().split()))
        xy_arr[i].append(x, y)
        
max_res = 0
for i in range(2 ** n):           
    ok_flg = True
    bin_i = format(i, "015b")[::-1]
                                    
        for j in range(n):
            for x, y in xy_arr[j]:　
                if bin_i[j] == 1 and y != int(bin_i[x - 1]):
                    ok_flg = False
                    break
            else:
                continue
            break
        
    if ok_flg:
        res = sum(int(x) for x in bin_i)
        mas_res = (max_res, res)
        
print(max_res)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    if not a: continue
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int16).T

def main():
    comb = (np.arange(1 << n)[:, None] >> np.arange(n) & 1).astype(np.bool)
    ok = np.full(1 << n, True)
    for i in range(n):
        if graph[i] is None: continue
        x, y = graph[i]
        ok &= ~comb[:, i] | np.all(comb[:, x-1] == y.astype(np.bool), axis=1)

    print(np.amax(comb[ok].sum(axis=1)))

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    if not a: continue
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int16).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    ok = np.full(1 << n, True)
    for i in range(n):
        if graph[i] is None: continue
        x, y = graph[i]
        bl = (comb[:, i] ^ 1) | np.all(comb[:, x-1] == y, axis=1)
        ok &= bl   
    print(np.amax(comb[ok].sum(axis=1)))

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    ok = []
    for i in range(n):
        x, y = graph[i]
        bl = (comb[:, i] ^ 1) | np.all(comb[:, x-1] == y, axis=1)
        ok.append(bl)
    ok = np.all(ok, axis=0)
    if not np.any(ok):
        print(0)
        return

    print(np.amax(comb[ok].sum(axis=1)))

if __name__ ==  '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
graph = [None] * n
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    graph[i] = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int8).T

def main():
    comb = np.arange(1 << n)[:, None] >> np.arange(n) & 1
    ok = []
    for i in range(n):
        x, y = graph[i]
        bl = (comb[:, i] ^ 1) | np.all(comb[:, x-1] == y, axis=1)
        ok.append(bl)
    ok = np.all(ok, axis=0)
    print(np.amax(comb[ok].sum(axis=1)))

if __name__ ==  '__main__':
    main()