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:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
cnt=[0 for i in range(n)]
x=[[]for i in range(n)]
for i in range(n):
    cnt[i]=int(input())
    for j in range(cnt[i]):
        x[i].append(list(map(int,input().split())))
lab=[0 for i in range(n)]
T=[0 for i in range(n)]
F=[0 for i in range(n)]
res2=0
def f(k,cnt2,res):
    global lab,x,cnt,T,F,res2,n
    if cnt2==n:
        # print(F)
        # print(lab)
        # print("--")
        for q,w in zip(F,lab):
            if (q>=1 and w==0) or (w>=1 and q==0):
                return
        #print("ok")
        my_sum=sum(lab)
        abc=lab.count(0)
        if abc>res2:
            res2=abc
                
    else:
        #k if False
        lab[k]+=1
        f(k+1,cnt2+1,res)
        lab[k]-=1
        #k is True
        T2=T.copy()
        F2=F.copy()
        for i in range(cnt[k]):
            if x[k][i][1]==0:
                F[x[k][i][0]-1]+=1
            else:
                T[x[k][i][0]-1]+=1
        f(k+1,cnt2+1,res+1)
        T=T2.copy()
        F=F2.copy()

f(0,0,0)
    

print(res2)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for i in range(n):
    for j in range(n):
        if i != j:
            if l[i][j]+l[j][i] == 1:
                TF[i] = 0
                TF[j] = 0
            if l[i][j]+l[j][i] == 0:
                Fset.append((i, j))
            for k in range(n):
                if l[i][j] >= 0 and l[i][j] != l[i][k]:
                    Fset.append((j,k))


print(Fset)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
l = list()
for n in range(N):
    a = int(input())
    tmp = list()
    for m in range(a):
        tmp.append([int(x) for x in input().split()])
    l.append(tmp)
honest = [1]*(N+1)
honest[0] = 0
for n in range(N-1):
    for m in l[n]:
        for k in range(n+1,N):
            for s in l[k]:
                if m[0] == s[0]:
                    if m[1] != s[1]:
                        honest[m[0]] = 0
                if m[0] == k+1 and s[0] == n+1:
                    if m[1] == 0 and s[1] == 0:
                        if honest[s[0]] == 1:
                            honest[s[0]] = 0
                            continue
                        if honest[m[0]] == 1:
                            honest[m[0]] = 0
                            continue
for n in range(1,N+1):
    if honest[n] == 1:
        for m in l[n-1]:
            if m[1] == 0:
                honest[m[0]] = 0
print(np.sum(honest))

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy
from pprint import pprint

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    aa = []
    for _ in range(N):
        aaa = []
        na = int(input())
        for _ in range(na):
            x,y = map(int,input().split())
            aaa.append((x-1,y==1))
        aa.append(aaa)
    #pprint(aa)

    # check
    ans = 0
    for i in range(N):
        result = [None]*N
        queue = list(range(N))
        queue.remove(i)  
        result[i] = True
        for x,y in aa[i]:
            result[x] = y
        #print(result)
        canceled = False

        while len(queue) != 0:
            target = queue.pop()
            canceled = False
            #print(target)
            if result[target] is None:
                continue
            for x,y in aa[target]:
                if not result[target]:
                    y = not y
                if result[x] != y:
                    canceled = True
                    break
                result[x] = y
            if canceled:
                #print("cancelled")
                break

        if canceled:
            continue

        tmpadd = 0
        for ii in range(N):
            if result[i] is None:
                skipped = False
                for x,y in aa[ii]:
                    if result[x] != i:
                        skipped = True
                        break
                if not skipped:
                    tmpadd += 1

        ans = max(ans, tmpadd + result.count(True))
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

_n = int(input())

said = []
for i in range(_n):
    ai = int(input())
    said.append([list(map(int, input().split())) for _ in range(ai)])

ans = 0
for i in range(2 ** _n):
    ynflg = 1
    flg = format(i, 'b').zfill(_n)
    for sy, tag in zip(said, flg):
        if tag == 0:
            continue

        for s in sy:
            if flg[s[0] - 1] != str(s[1]):
                ynflg = 0
                break

        if ynflg == 0:
            break

    if ynflg == 1:
        ans = max(ans, flg.count('1'))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
test = []
count = 0
for i in range(0, n):
    num_test = int(input())
    for j in range(0, num_test):
        answer = input().split()
        a = answer[1]
        if a == '1':
            count += 1
        else:
            continue
print(count)

Submission status: Wrong Answer

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

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

    syogen = [None] * (n)

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

    syogens.append(syogen)

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

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

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

    person_cnt[i] = sum([p for p in person if not None])

print(max(person_cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())

h = [[] for _ in [0]*(n+1)]
not_h = [[] for _ in [0]*(n+1)]

person = []
person2 = []
for i in range(n):
  An = int(input())
  for j in range(An):
    x,y = map(int,input().split())
    if y == 1:
      h[i+1] += [x]
      if not x in person:
        person += [x]
      
    elif y == 0:
      not_h[i+1] += [x]
      if not x in person2:
        person2 += [x]
    
if person:
  ans = len(person)    
  for p in person:
    if h[p]:
      for honesty in h[p]:
        if p in not_h[honesty]:
          ans -= 1
  print(ans)
  
else:
  print(len(person2)//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
h_list = ["h{}".format(x) for x in range(N)]
h_group = []
l_group = []

for i in range(N):
    talk_n = int(input())
    for j in range(talk_n):
        talk = list(map(int,input().split(' ')))
        # all honest
        if talk[1] == 1:
            h_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])
        else:
            pass
            # h_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        # all lier
        if talk[1] == 1:
            pass
            # l_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        else:
            l_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])
            
# print(h_group, l_group)
print(len(list(set(h_group))))

Submission status: Wrong Answer

Solution code:

n = int(input())

hp = 0

all_z = True

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0]*n
b=[0]*n
for j in range(n):
  a1 = int(input())
  for i in range(a1):
    c,d = map(int,input().split())
    if d == 0:
      b[c-1] = 1
    else:
      a[c-1] = 1
count = 0
for i in range(n):
  if a[i] != b[i]:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
cnt=[0 for i in range(n)]
x=[[]for i in range(n)]
for i in range(n):
    cnt[i]=int(input())
    for j in range(cnt[i]):
        x[i].append(list(map(int,input().split())))
lab=[0 for i in range(n)]
T=[0 for i in range(n)]
F=[0 for i in range(n)]
res2=0
def f(k,cnt2,res):
    global lab,x,cnt,T,F,res2,n
    if cnt2==n:
        # print(F)
        # print(lab)
        # print("--")
        for q,w in zip(F,lab):
            if (q>=1 and w==0):
                return
        #print("ok")
        my_sum=sum(lab)
        abc=n-my_sum
        if abc>res2:
            res2=abc
                
    else:
        #k if False
        lab[k]+=1
        f(k+1,cnt2+1,res)
        lab[k]-=1
        #k is True
        T2=T.copy()
        F2=F.copy()
        for i in range(cnt[k]):
            if x[k][i][1]==0:
                F[x[k][i][0]-1]+=1
            else:
                T[x[k][i][0]-1]+=1
        f(k+1,cnt2+1,res+1)
        T=T2.copy()
        F=F2.copy()

f(0,0,0)
    

print(res2)

Submission status: Wrong Answer

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


N = int(input())


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




def dfs(node, c, parent, arr):

    arr[node] = c
    for next, d in es[node]:
        #print(next, d, parent, arr)
        f = False
        if arr[next] != -1:
            if   d != arr[next]:
                ans[parent] = 0
                return
        if ans[next] != -1:
            if d != arr[next]:
                ans[parent] = 0
                return
        if arr[next] == -1:
            dfs(next, d, parent, arr)
        


ans = [-1] * N
ans [0] = 1
for i in range(N):
    tmp = [-1]*N
    for j in range(N):
        if ans[j] != -1:
            tmp[j] = ans[j]
            tmp[j] = 1
    dfs(i,tmp[i],i,tmp)

print(ans.count(1))

Submission status: Wrong Answer

Solution code:
N = int(input())

x_list = []
y_list = []
Group = []
A_list = []

for n in range(N):
    A = int(input())
    A_list.append(A)
    Group.append('none')
    x = []
    y = []
    for a in range(A):
        x_tmp, y_tmp = map(int, input().split())
        x.append(x_tmp)
        y.append(y_tmp)
    x_list.append(x)
    y_list.append(y)

ans = 0
flag = False

for i in range(N):
    for a_list in range(A_list[i]):
            if y_list[i][a_list] == 1:
                if Group[i] != 'false' and Group[x_list[i][a_list]-1] != 'false':
                    Group[i] = 'true'
                    Group[x_list[i][a_list]-1] = 'true'
                elif Group[i] != 'true' and Group[x_list[i][a_list]-1] != 'true':
                    Group[i] = 'false'
                    Group[x_list[i][a_list]-1] = 'false'
                elif Group[i] == 'true' and Group[x_list[i][a_list]-1] == 'false':
                    flag = True
                    break
                elif Group[i] == 'false' and Group[x_list[i][a_list]-1] == 'true':
                    flag = True
                    break
            if y_list[i][a_list] == 0:
                if Group[i] != 'true' and Group[x_list[i][a_list]-1] != 'false':
                    Group[i] = 'false'
                    Group[x_list[i][a_list]-1] = 'true'
                elif Group[i] != 'false' and Group[x_list[i][a_list]-1] != 'true':
                    Group[i] = 'true'
                    Group[x_list[i][a_list]-1] = 'false'                   
                elif Group[i] == 'true' and Group[x_list[i][a_list]-1] == 'true':
                    flag = True
                    break
                elif Group[i] == 'false' and Group[x_list[i][a_list]-1] == 'false':
                    flag = True
                    break


if flag:
    print(0)
else:
    print(max(Group.count('true'), Group.count('false')))

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
    if muri == 0:
        ans = max(ans, temp)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l1 =  [[2 for i in range(n)] for j in range(n)]
l2 =  [2 for i in range(n)] 
c = 0
d = 0
for i in range(0,n):
    a = int(input())
    for j in range(0,a):
        x,y = map(int,input().split())
        l1[x-1][i] = y
for i in range(0,2**n):
    i_str = format(i,'b')
    i_str = str(i_str)
    l0 = [0]*(n - len(i_str))
    l0 = l0 + list(i_str)
    l0 = [int(s) for s in l0]
    for j in range(0,n):
        if l0[j] == 1:
            for k in range(0,n):
                if l1[j][k] == 0:
                    l2[k] = 0
        else:
            for k in range(0,n):
                if l1[j][k] == 1:
                    l2[k] = 0
    for j in range(0,n):
        if l2[j] == 2:
            continue
        elif l2[j] != l0[j]:
            c = 1
            break
        else:
            continue
    if c == 0:
        if l0.count(1) > d:
            d = l0.count(1)
print(d)

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 = []
for i in tenchi:
  aa.append(sum(i))

print(min(aa))

Submission status: Wrong Answer

Solution code:
n = int(input()) # N

negs = [0 for _i in range(n)]
for i in range(n):
    m = int(input())
    for j in range(m):
        pos, neg = tuple(map(int, input().split()))
        negs[pos - 1] += neg - 1

print(sum([1 if x == 0 else 0 for x in negs]) if n > 2 else 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
lst = [format(i, '08b') for i in range(2**N)]
lst.reverse()
X = [[] for i in range(N)]
Y = [[] for i in range(N)]
ans_i = None
ans = 0
for i in range(N):
    tmp_A = int(input())
    A.append(tmp_A)
    for j in range(tmp_A):
        tmp_x,tmp_y = map(int,input().split())
        X[i].append(tmp_x)
        Y[i].append(tmp_y)
for i in lst:
    flag = 0
    PEOPLE = [j for j in i]
    for k in range(N):
        if PEOPLE[k]==1:
            LEN = len(X[k])
            for l in range(LEN):
                if PEOPLE[X[l]-1]!=Y[l]:
                    flag = 1
    if flag == 0:
        ans_i = i
        break
for i in ans_i:
    if i == 1:
        ans+=1
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  c = (int(input()))
  check = [0 for i in range(n)]
  for k in range(c):
    a, b = (map(int, input().split()))
    if b == 1:
      check[a-1] = 1
    elif b == 0:
      check[a-1] = -1
  ans.append(check)
  
count = 0
m = 0
for i in range(n):
  count = 0
  s = [ans[i][j] for j in range(n)]
  for j in range(n):
    if i != j:
      flag = True
      for k in range(n):
        if(s[k]==-1 and (s[k]+ans[j][k])>= 0) or (s[k]==1 and (s[k]+ans[j][k]) <= 0):
          flag = False
          break
      if flag:
        count+=1
    if count > m:
      m = count

print(m)

Submission status: Wrong Answer

Solution code:
import sys

inf = float("inf")

# import random
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pi,gcd
# from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

def dfs_t(current):
    global myset_true
    if current in myset_true:
        return
    myset_true.add(current)
    for child in true[current]:
        dfs_t(child)

def dfs_f(current):
    global myset_false,i
    if current in myset_false:
        return
    if current!=i:
        myset_false.add(current)
    for child in false[current]:
        dfs_f(child)


mod = 10**9+7

n = int(input())
true = {i:[] for i in range(1,n+1)}
false = {i:[] for i in range(1,n+1)}
for i in range(1,n+1):
    m = int(input())
    for j in range(m):
        x,y = get_ints()
        if y==1:
            true[i].append(x)
        else:
            false[i].append(x)
maxi = 0
for i in range(1,n+1):
    myset_true = set()
    dfs_t(i)
    # print(myset_true)
    myset_false = set()
    dfs_f(i)
    # print(myset_false)
    x = myset_true.intersection(myset_false)
    # print(x)
    if x==set():
        maxi = max(maxi, len(myset_true))
print(maxi)

Submission status: Wrong Answer

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

res = []

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

allp = 2**N - 1

for i in range(allp, -1, -1):
    pat = bin(i).replace('0b', '')
    pat = pat.zfill(N)
    h_list = []
    l_list = []
    for (i, p) in enumerate(pat):
        t = i + 1
        if p == '1':
            h_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
                else:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
            else:
                continue
            break
        else:
            l_list.append(t)
            for s in S[t]:
                if s[1] == 1:
                    if s[0] in h_list:
                        break
                    l_list.append(s[0])
                else:
                    if s[0] in l_list:
                        break
                    h_list.append(s[0])
            else:
                continue
            break
    else:
        res.append(pat)

maxA = 0
for r in res:
    maxA = max(maxA, r.count('1'))
print(maxA)

Submission status: Wrong Answer

Solution code:
N = int(input())
h_list = ["h{}".format(x) for x in range(N)]
h_group = []
l_group = []

for i in range(N):
    talk_n = int(input())
    for j in range(talk_n):
        talk = list(map(int,input().split(' ')))
        # all honest
        if talk[1] == 1:
            h_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])
        else:
            pass
            # h_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        # all lier
        if talk[1] == 1:
            pass
            # l_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        else:
            l_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])

print(list(set(h_group)))

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = dict()
cnt = 0

for i in range(N):
  Row=int(input())
  List=[list(map(int,input().split())) for i in range(Row)]
  cnt += 1
  dic[cnt]=List
  
shoujiki = []
uso = []
arr = []

for i in range(N):
  cnt = 0
  shoujiki.append(i+1)
  
  for j in range(N):
    a = dic[j+1]
    length = len(a)
    
    for k in range(length):
      if i > j:
        uso.append(j+1)
      elif j+1 in shoujiki:
        if dic[j+1][k][1] == 0:
          uso.append(dic[j+1][k][0])
        else:
          shoujiki.append(dic[j+1][k][0])
          
    shoujiki = list(set(shoujiki))
    
    shoujikilength = len(shoujiki)
    for l in range(shoujikilength):
      length2 = len(dic[shoujiki[l]])
      for m in range(length2):
        if dic[shoujiki[l]][m][1] == 0:
          uso.append(dic[shoujiki[l]][m][0])
    
    for l in range(shoujikilength):
      length2 = len(dic[shoujiki[l]])
      for m in range(length2):
        if dic[shoujiki[l]][m][1] == 1:
          if dic[shoujiki[l]][m][0] in shoujiki:
            uso.append(dic[shoujiki[l]][m][0])
    for l in range(shoujikilength):
      length2 = len(dic[shoujiki[l]])
      for m in range(length2):
        if dic[shoujiki[l]][m][1] == 1:
          if dic[shoujiki[l]][m][0] in shoujiki:
            uso.append(dic[shoujiki[l]][m][0])
    cnt = len(shoujiki)
    
    uso = list(set(uso))
    usolength = len(uso)
    for l in range(usolength):
      if uso[l] in shoujiki:
        cnt = cnt - 1
    arr.append(cnt)
  
  
  shoujiki = []
  uso = []
  
print(max(arr))

Submission status: Wrong Answer

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

tmp_true = [i+1 for i in range(N)]
tmp_false = []

# def remove_true(n,tmp_true):
    # if n in tmp_true:
    #     return tmp_true.remove(n)

#NG確定探し第一。OK　NGの組み合わせ
for idx,person in enumerate(A):
    for comment in person:
        try:
            if comment[1]==1 and [idx+1,0] in A[comment[0]-1]:
                tmp_false.append(idx+1)
        except:
            pass

#NG確定探し第２。OKOKの組み合わせ
for idx,person in enumerate(A):
    for comment in person:
        try:
            if comment[1]==1 and [idx+1,1] in A[comment[0]-1]:
                if idx+1 in tmp_false:
                    tmp_false.append(comment[0])
        except:
            pass

#NG確定探し第3。片道
for idx,person in enumerate(A):
    for comment in person:
        try:
            if comment[1]==1 and [idx+1,1] not in A[comment[0]-1]:
                if [idx+1,0] not in A[comment[0]-1]:
                    if comment[0]-1 in tmp_false:
                        tmp_false.append(idx+1)
            if comment[1]==0 and [idx+1,1] not in A[comment[0]-1]:
                if [idx+1,0] not in A[comment[0]-1]:
                    if comment[0]-1 not in tmp_false:
                        tmp_false.append(idx+1)
        except:
            pass

#NG確定探し第4。NGNG
for idx,person in enumerate(A):
    for comment in person:
        try:
            # print('--------')
            # print(comment[1])
            # print([idx+1,0])   
            # print(A[comment[0]-1])
            # print(comment[0]-1)
            if comment[1]==0 and [idx+1,0] in A[comment[0]-1]:
                # print('hit')
                # print(tmp_false)
                if idx+1 not in tmp_false and comment[0] not in tmp_false:
                        tmp_false.append(idx+1)


        except:
            pass


print(N-len(tmp_false))

Submission status: Wrong Answer

Solution code:
N=int(input())
SyoMax=0
syo=[set() for i in range(N)]
hus=[set() 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:
      hus[i].add(x)
    else:
      syo[i].add(x)
syoflag=[0]*N
syo2=[set() for i in range(N)]
hus2=[set() for i in range(N)]
for i in range(N):
  syotemp=set(syo[i])
  syozumi=set()
  hustemp=set(hus[i])
  husflag=0
  while len(syotemp^syozumi)>0:
    A=set(syotemp^syozumi)
    s=A.pop()
    
    syotemp|=set(syo[s-1])
    hustemp|=set(hus[s-1])
    syozumi.add(s)
    if len(syotemp&hustemp)>0:
      husflag=1
      break
  syo2[i]=set(syotemp)
  hus2[i]=set(hustemp)
  syoflag[i]=len(syotemp) 
  if (i+1) in syotemp:
    syoflag[i]-=1
  if husflag==1:
    syoflag[i]=-1

ref=set()
temp=-1
itemp=-1
for i in range(N):
  ref.add(i+1)
  if temp<syoflag[i]:
    temp=syoflag[i]
    itemp=i
if itemp>=0:
  i=itemp
  if syoflag[i]>=0:
    last=ref-(syo2[i]|hus2[i]|{i+1})    
    while len(last)>0:
      temp=-1
      jtemp=-1
      for j in last:
        if temp<syoflag[j-1]:
          temp=syoflag[j-1]
          jtemp=j-1
      if jtemp==-1:
        last.clear()
      elif len(syo2[i]&hus2[jtemp])>0 or len(syo2[jtemp]&hus2[i])>0:
        last.remove(jtemp+1)
      else:
        syo2[i]|= ({jtemp+1}|syo2[jtemp])
        hus2[i]|=hus2[jtemp]
        last.remove(jtemp+1)

  ansmax=len(syo2[i])
  if i+1 in syo2[i]:
    ansmax-=1
  print(ansmax+1)
else:
  print(0)

Submission status: Wrong Answer

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

t = []
l = []
ans = 0
flag = 0
f = 1
for i in range(n):
  if i+1 not in t and i+1 not in l:
    t_ = [i+1]
  flag = 1
  while(flag == 1):
    flag = 0
    t__ = [z for z in t_]
    t_ = []
    for m in t__:
      for j, k in zip(x[m],y[m]):
        if k == 0:
          if j in t or j in t_:
            f = 0
            t = []
            l = []
            t_ = []
            break
          l.append(j)
        if k == 1:
          if j in l:
            f = 0
            t = []
            l = []
            t_ = []
            break
          if j not in t and j not in t_:
            t_.append(j)
            flag = 1
      if f == 0:
        flag = 0
        t_ = []
        break
    t.extend(t_)
  if f != 0:
    ans = max(ans,len(t))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy
n = int(input())
a=[]
l=[]
for i in range(n):
    a.append(int(input()))
    di=[]
    for j in range(a[i]):
        x, y = (int(j) for j in input().split())

        l.append(di)
peaple=[-1 for i in range(n)]

print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
table = [[-1 for _ in range(N)]for __ in range(N)]
for i in range(N):
    for _ in range(int(input())):
        x,y = map(int,input().split())
        table[x-1][i] = y
ans = 0
for i in range(2**N):
    bit_s = bin(i)[2:][::-1]
    bit_s = bit_s + '0'*(N-len(bit_s))
    # print(bit_s)
    T = [int(bit_s[p]) for p in range(N)]
    t = [-1 for _ in range(N)]
    flag = True
    for p in range(N):
        if T[p]:
            for j,k in enumerate(table[p]):
                if k != -1:
                    if t[j] != (k+1)%2:
                        t[j] = k
                    else:
                        flag = False
    flag2 = True
    for p,q in zip(T,t):
        if p == 1:
            if q == 0:
                flag2 = False
        if q == 1:
            if p == 0:
                flag2 = False
    if flag and flag2:
        # print('!')       
        ans = max(ans,bit_s.count('1'))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
h_list = ["h{}".format(x) for x in range(N)]
h_group = []
l_group = []

for i in range(N):
    talk_n = int(input())
    for j in range(talk_n):
        talk = list(map(int,input().split(' ')))
        # all honest
        if talk[1] == 1:
            h_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])
        else:
            pass
            # h_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        # all lier
        if talk[1] == 1:
            pass
            # l_group.append(h_list[j])
            # l_group.append(h_list[talk[0]-1])
        else:
            l_group.append(h_list[j])
            h_group.append(h_list[talk[0]-1])
            
print(h_group, l_group)
print(list(set(h_group)))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
cnt=[0 for i in range(n)]
x=[[]for i in range(n)]
for i in range(n):
    cnt[i]=int(input())
    for j in range(cnt[i]):
        x[i].append(list(map(int,input().split())))
lab=[0 for i in range(n)]
T=[0 for i in range(n)]
F=[0 for i in range(n)]
res2=0
def f(k,cnt2,res):
    global lab,x,cnt,T,F,res2,n
    if cnt2==n:
        # print(F)
        # print(lab)
        # print("--")
        for q,w in zip(F,lab):
            if (q>=1 and w==0) or (w>=1 and q==0):
                return
        #print("ok")
        my_sum=sum(lab)
        abc=n-my_sum
        if abc>res2:
            res2=abc
                
    else:
        #k if False
        lab[k]+=1
        f(k+1,cnt2+1,res)
        lab[k]-=1
        #k is True
        T2=T.copy()
        F2=F.copy()
        for i in range(cnt[k]):
            if x[k][i][1]==0:
                F[x[k][i][0]-1]+=1
            else:
                T[x[k][i][0]-1]+=1
        f(k+1,cnt2+1,res+1)
        T=T2.copy()
        F=F2.copy()

f(0,0,0)
    

print(res2)