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 collections import defaultdict

N = int(input())
L = [[] for _ in range(N)]

if N == 1:
    print(1)
    exit()

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

ans = 0
for s in range(1 << N):
    honest = 0
    D = defaultdict(list)
    for i in range(N):
        if s >> i & 1:
            honest += 1
            D[i].append(1)
            for x, y in L[i]:
                D[x].append(y)
        else:
            D[i].append(0)
            for x, y in L[i]:
                if y == 0:
                    D[x].append(1)
                else:
                    D[x].append(0)

    mujun = False
    for k, v in D.items():
        if len(set(v)) != 1:
            mujun = True
        # if s >> k & 1:
        #     if v[0] == 0:
        #         mujun = True
        # else:
        #     if v[0] == 1:
        #         mujun = True

    if not mujun:
        ans = max(ans, honest)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = [[0 for _ in range(n)] for _ in range(n)]

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

tenchi = list(zip(*ans))

aa = 0
for i in tenchi:
  if sum(i) == n:
    aa += 1

print(aa)

Submission status: Wrong Answer

Solution code:
import itertools

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

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list()
for i in range(N):
    Ai = int(input())
    Alist = list()
    for j in range(Ai):
        x,y = map(int,input().split())
        Alist.append([x-1,y])
    li.append(Alist)
num =(2**(N))
while True:
    ok = True
    num -=1
    numlist = format(num, 'b')
    print(list(numlist))
    zero = str()
    if N != len(numlist):
        for i in range(N-len(numlist)):
            zero += "0"

        numlist = zero + numlist
    print(numlist)
    for i in range(len(numlist)):
        if numlist[i] == "1":
            for j in range(len(li[i])):
                if int(numlist[li[i][j][0]]) != li[i][j][1]:
                    ok = False
                    break
        if ok == False:
            break
    if ok == True:
        print(numlist.count("1"))
        break
    if num == 0:
        print(0)
        break

Submission status: Wrong Answer

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math
import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

    n = int(input())
    xy = [[] for i in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            xy[i].append(list(map(int,input().split())))
    b=[1 for i in range(n)]
    i=-1
    k=0
    while i<n-1:
        i+=1
        if b[i]==1:
            for j in xy[i]:
                if b[j[0]-1]!=j[1]:
                    b[i]=0
                    i=-1
                    break



#    print(b)
    print(sum(b))




#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

maxCnt = 0
for i in range(2 ** n):
    bin_str = format(i, 'b').zfill(n)
    trueFlg = 1
#    print(bin_str)
    for j in range(n):
        for k in B[j]:
            if bin_str[j] == '1':
                if int(bin_str[k[0] -1]) != k[1]:
                    trueFlg = 0
            if bin_str[j] == '0':
                if int(bin_str[k[0] - 1]) == k[1]:
                    trueFlg = 0
    if trueFlg == 1:
        maxCnt = max(maxCnt, bin_str.count('1'))

print(maxCnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo,syougen,flg
  for x,y in l:
    if seigo[x-1]==100:
      seigo[x-1]=y
      if y==1:
        search(syougen[x-1])
    elif seigo[x-1]!=y:
      flg=False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  seigo[i]=1
  _ans=0
  search(syougen[i])
  if flg:
    if sum(seigo)>100:
      for i,s in enumerate(seigo):
        if s==100:
          _seigo=seigo[:]
          flg=True
          seigo[i]=1
          search(syougen[i])
          if flg:
            pass
          else:
            seigo=_seigo[:]
    _ans=sum(seigo)%100
    if _ans>ans:
      ans=_ans
      maxseigo=seigo        
print(ans)

Submission status: Wrong Answer

Solution code:
import copy

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

print(X)

def rec(condition, i):
  if i==N:
    return condition.count(1)
  _X = X[i]
  _condition = copy.copy(condition)
  through_condition = copy.copy(condition)
  through_condition[i] = 0
  if condition[i]==0:
    return rec(copy.copy(through_condition), i+1)
  for x in _X:
    if _condition[ x[0]-1 ] == -1:
      _condition[ x[0]-1 ] = x[1]
    elif _condition[ x[0]-1 ] != x[1]:
      return 0 if _condition[i]==1 else rec(copy.copy(through_condition), i+1)
  _condition[i] = 1
  return max(rec(copy.copy(through_condition), i+1), rec(copy.copy(_condition), i+1))

print( rec([-1 for _ in range(N)], 0) )

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = [[-1 for _ in range(n)] for __ in range(n)]
for i in range(n):
    ai = int(input())
    for j in range(ai):
        hito, which = map(int, input().split())
        lst[i][hito-1] = which

ans = 0
muri = 0
for i in range(2**n):
    kumi = list(format(i, '0'+str(n)+'b'))
    temp = 0
    for j in range(n):
        if muri == 1:
            muri = 0
            break
        elif kumi[j] == '1':
            for k in range(n):
                if (lst[k][j] == 0 and kumi[k] == '1') or (lst[j][k] == 1 and kumi[k] == '0'):
                    muri = 1
                    break
            if muri == 0:
                temp += 1
    ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

testinomy = [[-1 for _ in range(N)] for _ in range(N)]

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

ans = 0

for honests in range(N ** 2 - 1):
    bit = '{:015b}'.format(honests)[::-1]
    ok_flag = True
    for i in range(N):
        if bit[i] == '1':
            for j, k in enumerate(testinomy[i]):
                str_k = str(k)
                if str_k != '-1':
                    if str_k == '1' and bit[j] == '1':
                        pass
                    elif str_k == '0' and bit[j] == '0':
                        pass
                    else:
                        ok_flag = False
                        break
        if ok_flag == False:
            break
    if ok_flag:
        ans = max(ans, sum(map(int, bit)))

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
info = np.ones((n,n))*2
double_lie = 0
douretu = 0

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

for i in range(n):
  for j in range(n):
    if info[i,j] == 0 and info[j,i] == 0:
      double_lie += 1
      
for i in range(n):
  if np.count_nonzero(info[:,i]==1) > 0 and len(info[:,i])-np.count_nonzero(info[:,i]) > 0:
    douretu += 1
    
print(n-max(0,double_lie-1)-douretu)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = []
for i in range(N):
    M = int(input())
    T = {}
    for _ in range(M):
        x, y = map(int, input().split())
        T[x] = y
    A.append(T)

def solve(i):
    memo = {}
    for j in range(N):
        for x, y in A[j].items():
            if i >> j & 1:
                if x in memo and memo[x] != y:
                    return False
                memo[x] = y
            else:
                if x in memo and memo[x] == y:
                    return False
                memo[x] = (1 - y)
    for x, y in memo.items():
        if i >> x & 1 and y != 1:
            return False
    return True

ans = 0
for i in range(2 ** N):
    if solve(i):
        ans = max(ans, bin(i).count("1"))

print(ans)

Submission status: Wrong Answer

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

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

ans = 0
for i in range(N):
    cand = collect[i]
    flag = True
    for j in cand:
        if not collect[j] == cand:
            flag = False
    if flag:
        ans = max(ans, len(cand))

print(ans)

Submission status: Wrong Answer

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

count=0
while count < N:
    A = int(input())
    temp = []
    in_count = 0
    while in_count < A:
        l=list(map(int, input().split()))
        temp.append( l )
        in_count += 1
    evid.append(temp)
    count += 1

#print(evid)

all_pattern = 2**N

max_num = 0
for pattern in range(all_pattern+1):
    break_flag = False
    for ii in range(N):
        person_evid = (pattern>>ii) & 1
        #print(pattern, ii, person_evid)
        for temp_evid in evid[ii]:
            if person_evid == 1 and (pattern>>(temp_evid[0]-1) ) & 1 != temp_evid[1]:
                break_flag = True
            if person_evid == 0 and (pattern>>(temp_evid[0]-1) ) & 1 == temp_evid[1]:
                break_flag = True
            if break_flag:
                #print(pattern, ii, person_evid)
                break

        if break_flag:
            break
    if break_flag:
        continue
    num = 0
    for ii in range(N):
        num += (pattern>>ii) & 1
    if max_num < num:
        max_num = num
print(max_num)

Submission status: Wrong Answer

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

for i in range(N):
    A = int(input())
    for _ in range(A):    
        x, y = map(int, input().split())
        if y == 0:
            AT[i] = False 
        else:
            AT[i] = True


if (1 not in AT):
    if N == 2:
        print(1)
    else:
        print(0)
else:
    cnt = AT.count(1)
    print(max(cnt, N-cnt))

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

person = [x for x in range(N)]

for h_num in reversed(range(N + 1)):
    for h_ppl in combinations(person, h_num):
        ppl = [0] * N
        for i in h_ppl:
            ppl[i] = 1

        for a in person:
            for testimony in A[a]:
                if (ppl[a] == 1 and testimony[1] == ppl[testimony[0]]) or (ppl[a] == 0):
                    continue
                else:
                    break
            else:
                continue
            break
        else:
            print(h_num)
            exit(0)
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
s_max = 0

q_li = []
for i in range(N):
    q = []
    for _ in range(int(input())):
        a, b = map(int,input().split())
        q.append((a,b)) 
    q_li.append(q)

def f(q_li, i):
    for n, q in enumerate(q_li):
        for a,b in q:
            a = a-1
            if (i >> n) & 1:
                if (i >> a & 1) != b:
                    return 0
            elif (i >> a & 1) == b:
                return 0
    return str(bin(i)).count('1')

for i in range(2 ** N):
    res = f(q_li, i)
    if res > s_max:
        s_max = res 
        
print(s_max)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
persons = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        persons[i].append([x-1, y])
ans = 0
amax = 0
b = [[] for _ in range(n)]
for i in range(2**n):
    tmp = np.array([i >> j & 1 for j in range(n)])
    for q, k in enumerate(tmp):
        if k == 1:
            for person in persons[q]:
                b[person[0]].append(person[1])
        else:
            for person in persons[q]:
                if person[1] == 1:
                    b[person[0]].append(0)
                else:
                    b[person[0]].append(1)
    flag = 0
    c = 0
    for b1 in b:
        if len(set(b1)) > 1:
            flag = 1
        if list(set(b1)) == [0]:
            c += 1

    if len(b) == c:
        flag = 1
    if flag == 0:
        print(tmp)
        for t in tmp:
            if t == 1:
                ans += 1

    if amax < ans:
        amax = ans
    ans = 0
    b = [[] for _ in range(n)]
print(amax)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

person = [x for x in range(N)]

for h_num in reversed(range(N + 1)):
    for h_ppl in combinations(person, h_num):
        ppl = [0] * N
        for i in h_ppl:
            ppl[i] = 1

        for a in person:
            for testimony in A[a]:
                if (ppl[a] == 1 and testimony[1] == ppl[testimony[0]]) or (ppl[a] == 0 and testimony[1] != ppl[testimony[0]]):
                    continue
                else:
                    break
            else:
                continue
            break
        else:
            print(h_num)
            exit(0)
        break

print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
xys = []
for k in range(n):
    a = int(input())
    xys.append([])
    for i in range(a):
        xy = list(map(int, input().split()))
        xy[0] -= 1
        if xy[1] == 0:
            xy[1] = -1
        xys[-1].append(xy)
        

best = 0
for l in range(n):
    hantei = [0 for _ in range(n)]
    hantei[l] = 1
#     xys = xys[1:] + [xys[0]]
    flag = 0
    que = [l]
    done = []
    while len(que) > 0:
        i = que[0]
        if i in done:
            que = que[1:]    
            continue
        a = xys[i]
        done.append(i)

#     for i, a in enumerate(xys):
        #print("---")
        #print("done", done)
        #print("que", que)
        #print("han", hantei)
        #print("flag", flag)
        #print("a", a)
        for k, b in enumerate(a):
            if b[0] not in done:
                que.append(b[0])
            #print("b", b)
            if hantei[b[0]] == 0:
                hantei[b[0]] = b[1]
                if b[1] == -1:
                    done.append(b[0])
                #print("hantei", hantei)
            else:
                if hantei[b[0]] == b[1]:
                    pass
#                     if hantei[i] == -1:
#                         flag = -1
#                         #print("bad***")
#                         break
                else:
                    if hantei[i] == 1:
                        flag = -1
                        #print("bad***")
                        break
                    else:
                        hantei[i] = -1
            if flag == -1:
                break
        if flag == -1:
            break
        #print("que", que)
        
    if flag == 0:
        if best < np.sum(np.array(hantei) == 1):
            best = np.sum(np.array(hantei) == 1)


print(best)

Submission status: Wrong Answer

Solution code:
def examC():
    N = I()
    A = [0]*N; xy = [[] for _ in range(N)]
    for i in range(N):
        A[i] = I()
        for j in range(A[i]):
            s1,s2 = LI()
            xy[i].append([s1,s2])
#    print(xy)
    loop = 2**N; differ = 2**4
    ans = 0
    for i in range(loop):
        uso = [False]*N
        cur = 0
        for j in range(N+1):
            if i&(2**j)==(2**j):
                cur +=1
#        print(i,cur)
        for j in range(N):
            if i&(2**j)==(2**j):
                for k in xy[j]:
                    if k[1]==0:
                        uso[k[0]-1] = True
#チェック
        for j in range(N):
            if uso[j] and i&(2**j)==(2**j):
                cur = 0
                break
            if not uso[j] and i&(2**j)==0:
                cur = 0
                break
        ans = max(ans,cur)
    print(ans)

    return

def examD(mod):
    N = I(); A = LI()
    d = defaultdict(int)
    for i in range(N):
        cur = A[i]
        j = 1
        while(cur>0):
            if cur&1==1:
                d[j] +=1
            j +=1
            cur >>=1
    ans = 0
    for i,j in d.items():
        ans += j*(N-j) * 2**(i-1)
        ans %=mod
    print(ans)
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Submission status: Wrong Answer

Solution code:
N = int(input())
remark = [0] * N
NGlist = [0] * N
grouplist = [0]*N
ans = 0
for i in range(N):
    remark[i] = [-1] * N
    NGlist[i] = [0] * N
    grouplist[i] = [0] * N


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

for num in range(2 ** N):
    # print("num=")
    # print(num)
    group = set()
    for h in range(N):
        if h not in group and num % 2 == 1:
            group.add(h)
            for s in range(N):
                if grouplist[h][s] == 1 and s not in group:
                    group.add(s)
        num //= 2
    len_group = len(group)
    # print(group)
    # if ans >= len_group:
    #    flag = 1
    flag = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
 
N=int(input())
box = [1]*N

chk=0
for i in range(N):
  Ai = int(input())
  for j in range(Ai):
    x,y=map(int,input().split())
    if y==0:
      box[x-1]=y
    else:
      chk=1

total=sum(box)
if total == 0 and chk == 0:
  print(1)
elif total == 0 and chk==1:
  print(0)
else:
  print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
A =[set() for i in range(N)]
for i in range(N):
  M = int(input())
  for j in range(M):
      x,y = map(int,input().split())
      A[x-1].add(y)
if(N - A.count({0,1}))==0:
  print(0)
else :
  if A.count({0}) > 0:
    print(N - A.count({0,1})-A.count({0})+1)
  else:
    print(N - A.count({0,1}))

Submission status: Wrong Answer

Solution code:
def main():
    # input
    n = int(input())

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

    # calc
    ans = 0
    flag = False
    for num in range(1, 2**n):
        num = bin(num)[2:].rjust(n, '0')
        for i in range(len(li)):
            if num[i] == '1':
                for j, key in enumerate(li[i]):
                    if num[key-1] != str(li[i][key]):
                        flag = True
                        break
                if flag:
                    flag = False
                    break
        else:
            # print(num, ans)
            ans = max(num.count('1'), ans)
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = []
ans = 0
for i in range(N):
    A = int(input())
    l = []
    for j in range(A):
        x, y = map(int, input().split())
        l.append([x, y])
    xy.append(l)
# print(xy)

#bit全探索
#bitたつ→正直者
#bitたたない→不親切もの
tmp = [-1 for _ in range(N)]
for i in range(2 ** N):
    tmp = [-1 for _ in range(N)]
    flag = True
    cnt = 0
    for j in range(N):
        if i >> j & 1:
            #正直者
            cnt += 1
            A = xy[j]
            for k in A:
                _x = k[0] - 1
                _y = k[1]
                if tmp[_x] == -1:
                    tmp[_x] = _y
                elif tmp[_x] != -1 and tmp[_x] ==_y:
                    pass
                else:
                    flag = False
                if tmp[j] == -1:
                    tmp[j] = 1
                elif tmp[j] != 1:
                    flag = False
        else:
            #不親切もの
            A = xy[j]
            for k in A:
                _x = k[0] - 1
                _y = k[1]
                if tmp[_x] == -1:
                    if _y == 0:
                        tmp[_x] = 1
                    elif _y == 1:
                        tmp[_x] = 0
                elif tmp[_x] != -1 and tmp[_x] !=_y:
                    pass
                else:
                    flag = False
                if tmp[j] == -1:
                    tmp[j] = 0
                elif tmp[j] != 0:
                    flag = False

    if flag:
        ans = max(ans, sum(tmp))
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
p=0
Q=[]
M=0
while p<N:
    A=int(input())
    M+=A
    for i in range(A):
        x=list(map(int,input().split()))
        x.insert(0,p+1)
        Q.append(x)
    p=p+1

K=0
for i in range(M):
    for j in range(M):
        if Q[i][0]==Q[j][1] and Q[i][1]==Q[j][0] and Q[i][2]!=Q[j][2]:
            K+=1
if N-K-1>0:
    print(N-K-1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = [1]*N
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        lst[x-1] += y
ans = max(lst)
if ans != len(lst):
    for i in lst:
        if ans == i:
    	    continue
        else:
            print(ans)
            exit()
    if len(lst) == 2:
        print(1)
    else:
        print(0)
else:
    print(ans)

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()))
        tmp.append(h)
    shou.append(tmp)
#print(shou)
for i in range(2**N-1):
    flag=True
    tmp=str(bin(katei))[2:].zfill(N)
    state=[-1 for _ in range(N)]
    #print(tmp)
    #print()
    for j in range(N):
        #print(tmp[j])
        for k in shou[j]:
            #print(k)
            
            if tmp[j]=="0":
                if state[k[0]-1]!=-1 and state[k[0]-1]!=1-k[1]:
                    #print("false")
                    flag=False
                state[k[0]-1]=1-k[1]
            else:
                if state[k[0]-1]!=-1 and state[k[0]-1]!=k[1]:
                    #print("falkse")
                    flag=False
                state[k[0]-1]=k[1]
            #print(state)
    if flag:
        #print("collect:",tmp)
        ans=max(ans,tmp.count("1"))
            
            
    katei+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
c = 0
m = np.full((N, N), 2)
for i in range(N):
    a = int(input())
    for j in range(a):
        x,y=[int(k) for k in input().split()]
        x = x -1
        m[i,x] = y
        if (m[x,i] == 1) and (m[i,x] == 1):
            c = c + 2
        elif (m[x,i] == 0) and (m[i,x] == 0):
            c = c + 1
            
print(c)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
L = [[] for _ in range(N)]

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

ans = 0
for s in range(1 << N):
    honest = 0
    D = defaultdict(list)
    for i in range(N):
        if s >> i & 1:
            honest += 1
            D[i].append(1)
            for x, y in L[i]:
                D[x].append(y)
        else:
            D[i].append(0)
            for x, y in L[i]:
                if y == 0:
                    D[x].append(1)
                else:
                    D[x].append(0)

    mujun = False
    for k, v in D.items():
        if len(set(v)) != 1:
            mujun = True

    if not mujun:
        ans = max(ans, honest)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        dic[i].append((x-1,y))
# print(dic)

ans = []
for i in range(N):
    p = [-1] * N
    p[i] = 1
    for x,y in dic[i]:
        p[x] = y
    flg = True
    for j in range(N):
        if j == i: continue
        for xj,yj in dic[j]:
            if p[j] == 0:
                if yj == 1: yj = 0
                elif yj == 0: yj = 1
            if p[xj] != yj:
                if p[j] == -1: p[j] = 0
                else:
                    flg = False
                    break
        if not flg:
            p = [0]
            break
    ans.append(p.count(1)+p.count(-1))
print(max(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
remark = [0] * N
NGlist = [0] * N
grouplist = [0]*N
ans = 0
for i in range(N):
    remark[i] = [-1] * N
    NGlist[i] = [0] * N
    grouplist[i] = [0] * N


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

for num in range(2 ** N):
    # print("num=")
    # print(num)
    group = set()
    for h in range(N):
        if h not in group and num % 2 == 1:
            group.add(h)
            for s in range(h+1, N):
                if grouplist[h][s] == 1 and s not in group:
                    group.add(s)
        num //= 2
    len_group = len(group)
    # print(group)
    # if ans >= len_group:
    #    flag = 1
    flag = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
while True:
  try:
    L.append(list(map(int,input().split())))
  except:
    break
I={}
g=0
t=0
for l in L:
  try:
    if l[0] not in I:
      I.setdefault(l[0],l[1])
    else:
      if I[l[0]]!=l[1]:
        g+=1
      else:
        t+=1
  except:
    pass
I2={}
l2=0
t2=0
for l in L[::-1]:
  try:
    if l[0] not in I2:
      I2.setdefault(l[0],l[1])
    else:
      if I2[l[0]]!=l[1]:
        l2+=1
      else:
        t2+=1
  except:
    pass
if max(t,t2)==0 and max(g,l2)==0:
  print(N-1)
else:
  print(N-min(g,l2))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
xy=[]

sum=0
answer=N
base=0

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

for k in range(N):
    sum+=A[k]
for l in range(sum):
    if [l+1, 0] in xy and [l+1, 1] in xy:
        answer-=1
for m in range(sum):
    for n in range(sum):
        if n!=m:
            if [m, 1] in xy:
                pass
            else:
                if [m, 0] in xy and [n+m, 0] in xy:
                    base+=1
answer-=base    

print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
import numpy as np
matrix = np.zeros((N,N),dtype="int8")
for n in range(N):
    A = int(input())
    for a in range(A):
        array = [int(i) for i in input().split()]
        matrix[n,array[0]-1] = 1 if array[1] == 1 else -1
ans = 0
for mat in matrix:
    if sum(mat) == sum(abs(mat)):
        ans += 1
print(ans)