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())
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)

def dfs(n):
    if n == N: return
    

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

Submission status: Wrong Answer

Solution code:
num_person=int(input())
tests_list = []
test_score_dict = {}
for p in range(num_person):
    num_tests=int(input())
    tests=[list(map(int, input().split())) for t in range(num_tests)]
    tests_list.append(tests)
    test_score_dict[p+1] = 1
for unkinds in range(num_person+1):
    honests = num_person - unkinds
    for i in range(num_person):
        num_target_person = len(tests_list[i])
        for n in range(num_target_person):
            target_person = tests_list[i][n][0]
            target_person_test = tests_list[i][n][1]
            test_score_dict[target_person] *= target_person_test
    contra = honests - sum(test_score_dict.values())
    if honests + contra <= num_person:
        print(honests)
        exit()
print(0)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    # input = sys.stdin.readline
    N = int(input())

    test = [dict() for _ in range(N)]

    count = 0

    for i in range(N):
        M = int(input())
        if M == 0:
            count += 1
        for _ in range(M):
            j, b = map(int, input().split())
            test[i][j-1] = bool(b)

    base_set = set(list(range(N)))

    for i in range(N):  # iが正直者と仮定
        honest = set()
        honest.add(i)
        lier = set()
        for j, b in test[i].items():  # 正直者の証言を作成
            if b:
                honest.add(j)
                for g, r in test[j].items():
                    if r:
                        honest.add(g)
                    else:
                        lier.add(g)
            else:
                lier.add(j)
        candidate = len(honest)
        for j in honest:  # 検証
            for g, r in test[j].items():
                if r:
                    if g in lier:
                        candidate = 0
                if not r:
                    if g in honest:
                        candidate = 0
        not_in = base_set - honest - lier
        for j in not_in:
            cand_n = 1
            for g, r in test[j].items():
                if r:
                    if g in lier:
                        cand_n = 0
                if not r:
                    if g in honest:
                        cand_n = 0
            candidate += cand_n

        count = max(count, candidate)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n  = int(input())
xs = []
hs = [True] * n

for _ in range(0, n):
	xs.append([None] * n)

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

print(xs)

Submission status: Wrong Answer

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

n = int(input())

comment_list = [ [] for i in range(n) ]
for i in range(n):
    m = int (input())
    for j in range(m):
        a, b = [ int(v) for v in input().split() ]
        comment_list[i].append([a-1,b])

ans = 0
for i in range(2**n):
    s = bin(i)[2:].zfill(n)
    status = 1
    for j, v in enumerate(s):
        p = int(v)
        for x, y in comment_list[j]:
            if v == "1":
                if s[x] != str(y):
                    status = 0
            elif v == "0":
                if s[x] == str(y):
                    status = 0
    if status == 1:
        ans = max(ans, s.count("1"))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

xdic = {}
ydic = {}
for i in range(N):
    xdic[i+1] = []
    ydic[i+1] = []
    A = int(input())
    for j in range(A):
        x,y = map(int, input().split())
        xdic[i+1].append(x)
        ydic[i+1].append(y)

# print(xdic, ydic)
templi = []
for i in range(N):
    y = ydic[i+1]
    x = xdic[i+1]
    temp = ['a' for i in range(N)]
    for j in range(len(x)):
        if y[j] == 0:
            temp[x[j]-1] = 'b'
    templi.append(temp)


ansdic = {}
for i in range(len(templi)):
    if ''.join(templi[i]) not in ansdic.keys():
        ansdic[''.join(templi[i])] = 1
    else:
        ansdic[''.join(templi[i])] += 1

# print(ansdic)
if N == 2:
    if templi[0] == templi[1]:
        print(2)
    else:
        print(1)
else:
    values = ansdic.values()
    m = max(list(values))
    if m == 1:
        print(0)
    else:
        print(m)

Submission status: Wrong Answer

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

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

for i in range(2 ** n):
    b = str(bin(2**n-1-i)).ljust(2+n, "0")
    flag = "t"
    for j in range(n):
        if b[2+j] == "1":
            for k in range(len(l[j])):
                if l[j][k][1] == 1:
                    if b[l[j][k][0]+1] == "0":
                        flag = "f"
                        break
                if l[j][k][1] == 0:
                    if b[l[j][k][0]+1] == "1":
                        flag = "f"
                        break
        if flag == "f":
            break

        if j == n-1:
            print(b.count("1"))
            sys.exit()
        

print("0")

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):
        x,y=list(map(int,input().split()))
        x-=1
        tmp.append([x,y])
    shou.append(tmp)
#print(shou)
for i in range(2**N-1):
    flag=True
    tmp=str(bin(katei))[2:].zfill(N)
    #print(tmp)
    #print()
    #print()
    for j in range(N):
        #print(tmp[j])
        #print(tmp[j])
        for k in shou[j]:
            #print(k)
            #print(tmp[k[0]])
            #print()
            if tmp[j]=="0":
                if tmp[k[0]]==str(k[1]):
                    #print("false")
                    flag=False
            else:
                if tmp[k[0]]!=str(k[1]):
                    #print("falkse")
                    flag=False
            #print(state)
    if flag:

        #print("collect:",tmp)
        ans=max(ans,bin(katei).count("1"))
            
            
    katei+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for _ in range(n):
    m = int(input())
    l.append([[int(i) for i in input().split()]for _ in range(m)])
    
ans = [float('inf') for _ in range(n)]

for i in l:
    for j in i:
        print(i,j,ans)
        if ans[j[0]-1] != j[1] and ans[j[0]-1] != float('inf'):
            ans[j[0]-1] = 0
        else:
            ans[j[0]-1] = j[1]
            
if sum(ans) == 0:
    print(1)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
N = int(input())
import itertools
TF = [0,1]
All = list(itertools.product(TF, repeat=N))
lis_A = [0]
lis_x = []
lis_y = []
ans = 0
for i in range(N):
  A = int(input())
  lis_A.append(A)
  for j in range(A):
    x,y = map(int,input().split())
    lis_x.append(x-1)
    lis_y.append(y)
for p in range(1,N+1):
  lis_A[p] = lis_A[p-1]+lis_A[p]
for k in range(len(All)):
  L = All[k]
  jud = True
  for g in range(N):
    if L[g] == 1:
      for q in range(lis_A[g],lis_A[g+1]):
        if L[lis_x[q]] != lis_y[q]:
          jud = False
    else:
      for q in range(lis_A[g],lis_A[g+1]):
        if L[lis_x[q]] == lis_y[q]:
          jud = False
  if jud:
    ans = max(sum(L),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    G = [[] for _ 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())
            G[x-1].append((i, y))
            # x - 1は人iからyと言われている

    ans = 0
    for bit in range(1 << N):
        cur = 0
        good = True  # 矛盾がない
        for i in range(N):
            if bit & (1 << i):
                # 人iは正直者
                for j, y in G[i]:
                    if bit & (1 << j) and y == 0:
                        # 人jは正直者
                        good = False
                        break
                    elif not(bit & (1 << j)) and y == 1:
                        # 人jはうそつき
                        good = False
                        break
                cur += 1
        if good:
            ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [0 for i in range(N)]

arr = [[0 for i in range(N)] for j in range(N)]

unkind = 0

for n in range(N):
    A[n] = int(input())
    for m in range(A[n]):
        S1,S2 = map(int, input().split())
        arr[n][S1 - 1] = S2

for n in range(A[n]):
    for l in range(A[n] + 1):
        if(arr[n][l] != arr[n + 1][l]):
            unkind += 1
            break

        else:
            pass

print(N - unkind)
        
pass

Submission status: Wrong Answer

Solution code:
N = int(input())
xy = [[-1] * N for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    x, y = map(int, input().split())
    xy[i][x-1] = y
#print(xy)
for i in range(N):
  xy[i][i] = 1

count = 0
for i in range(N):
  count0 = 0
  count1 = 0
  for j in range(N):
    if xy[j][i] == 0:
      count0 += 1
    elif xy[j][i] == 1:
      count1 += 1
  if count1 * count0 != 0:
    count += 1
print(max(N - count, 1))

Submission status: Wrong Answer

Solution code:
a = int(input())
x = []
y = []
plis = [[],[],[]]
sender = []
getter = []
flag = []

for k in range(a):
    j = int(input())
    
    for i in range(j):
        x1,y1=[int(i) for i in input().split()]
        x.append(x1)
        y.append(y1)
        sender.append(k+1)
        getter.append(x1)
        flag.append(y1)


#print(sender)
#print(getter)
#print(flag)

map = []
#map.append(sender)
map.append(getter)
map.append(flag)

#print(map)

c = int(0)

anc = 0

f = 0

for e in range(len(flag)):
    if(flag[e] == 0):
        anc = anc + 1

if(anc == len(flag) and len(flag) == a):
    print(int(a/2))
    f = 1


if(f == 0):
    for q in range(len(getter)):
        for w in range(len(getter)):
            if(q == w):
                continue
            #print(getter[q],getter[w])
            if(getter[q] == getter[w]):
                if(flag[q] != flag[w]):
                    #print("kitakita",getter[q],getter[w])
                    c = c + 1

    print(int(a - (c / 2)))

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)
        if arr[next] != -1:
            if arr[node] == 1 and  d != arr[next]:
                arr[parent] = 0
        else:
            dfs(next, d, parent, arr)
        


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

print(ans.count(1))

Submission status: Wrong Answer

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

hito=[True]*N
for i in range(N-1):
    for j in range(i+1,N):
        if table[i][j]==1:
            if table[j][i]==1 or table[j][i]==None:
                continue
            else:
                hito[i]=False
                break
        if table[i][j]==0:
            if table[j][i]==None:
                continue
            else:
                hito[j]=False
                break
for i in range(N-1):
    if hito[i]==True and table[N-1][i]==0:
        hito[N-1]=False
    if hito[i]==False and table[N-1][i]==1:
        hito[N-1]=False

cnt=0
for i in range(N):
  if hito[i]==True:
    cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC147 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = [[] for _ in range(n)]
for i in range(n):
    a = I()
    for _ in range(a):
        x,y = LI()
        lst[x-1].append((i,y))
f = defaultdict(int)
ans = n
for i in range(n):
    true = []
    false = []
    for j,k in lst[i]:
        if f[j]:
            continue
        if k == 1:
             true.append(j)
        else:
            false.append(j)
    if len(true) != 0 and len(false) != 0:
        st,sf = 0,0
        for j in true:
            st += len(lst[j])
        for j in false:
            sf += len(lst[j])
        if st >= sf:
            for j in false:
                f[j] = 1
                ans -= 1
        else:
            f[i] = 1
            ans -= 1
            for j in true:
                f[j] = 1
                ans -= 1
    elif len(false) != 0:
        ans -= 1
        f[i] = 1
    elif len(true) != 0 and f[i]:
        for j in true:
            f[j] = 1
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())


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')

s_max = 0
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:
N = int(input())
xy = [[-1] * N for i in range(N)]
for i in range(N):
  A = int(input())
  for j in range(A):
    x, y = map(int, input().split())
    xy[i][x-1] = y
#print(xy)
for i in range(N):
  xy[i][i] = 1

count = 0
for i in range(N):
  count0 = 0
  count1 = 0
  for j in range(N):
    if xy[j][i] == 0:
      count0 += 1
    elif xy[j][i] == 1:
      count1 += 1
  if count1 * count0 != 0:
    count += 1
print(min(N - count, 1))

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
N = int(input())
memo = [[1] * N for _ in range(N)]
count = 0
for i in range(N):
    for j in range(int(input())):
        pos, flg = map(int, input().split())
        memo[pos - 1][i]= flg
for i in range(N):
    if min(memo[i]) == 1:
        count += 1
print(count)

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)
        if arr[next] != -1:
            if arr[node] == 1 and  d != arr[next]:
                arr[parent] = 0
        else:
            dfs(next, d, parent, arr)
        


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

print(ans.count(1))

Submission status: Wrong Answer

Solution code:
N=int(input())
C=[[2 for i in range(N)] for j in range(N)]
#print(C)
 
for i in range(N):
    An=int(input())
    Ln=[list(map(int, input().split())) for j in range(An)]
    for k in range(len(Ln)):
        C[i][Ln[k][0]-1]=Ln[k][1]
 
Ans=0
 
for i in range(N):
    for j in range(N):
        if C[i][j]==C[j][i]==1:
            Ans+=2
        elif C[i][j]==C[j][i]==0:
            Ans+=1
        elif C[i][j]==1 and C[j][i]==2:
            Ans+=2
    
print(Ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [None for _ in range(n)]
penalty = 0
for i in range(n):
    c = int(input())
    if i == 0:
        a[0] == 1
    for j in range(c):
        x, y = map(int, input().split(' '))
        if i == 0:
            a[x-1] = y
        else:
            if a[x-1] != y:
                penalty += 1
            else:
                a[x-1] = y
            
            if a[i] != 1:
                penalty +=1
            else:
                a[i] = 1
        # print(a)
        
if penalty > n:
    print(0)
else:
    print(penalty-1)

Submission status: Wrong Answer

Solution code:
import itertools

n = int(input())

speak = [[] for _ in range(n)]


for i in range(n):
    s = int(input())
    for j in range(s):
        a,b = map(int,input().split())
        tal = (a-1,b)
        speak[i].append(tal)

check = 0

b = [i for i in range(n)]
c = len(b)

b_pairs = []
for i in range(1,n+1):
    b_pairs += list(itertools.combinations(b,i))

for i in b_pairs:
    tru = []
    for j in i:
        tru.append(j)
    
    leng = len(tru)
    if leng <= check:
        break
        
    for k in tru:
        z = 1
        for d,e in speak[k]:
            if d in tru:
                if e == 1:
                    continue
                else:
                    z = 0
            else:
                if e == 0:
                    continue
                else:
                    z = 0
        if z == 0:
            break
    else:
        check = leng
            
print(check)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#ABC147 C

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = [[] for _ in range(n)]
for i in range(n):
    a = I()
    for _ in range(a):
        x,y = LI()
        lst[x-1].append((i,y))
f = defaultdict(int)
ans = n
for i in range(n):
    true = []
    false = []
    for j,k in lst[i]:
        if f[j]:
            continue
        if k == 1:
             true.append(j)
        else:
            false.append(j)
    if len(true) != 0 and len(false) != 0:
        st,sf = 0,0
        for j in true:
            st += len(lst[j])
        for j in false:
            sf += len(lst[j])
        if st > sf:
            for j in false:
                f[j] = 1
                ans -= 1
        else:
            f[i] = 1
            ans -= 1
            for j in true:
                f[j] = 1
                ans -= 1
    elif len(false) != 0:
        ans -= 1
        f[i] = 1
    elif len(true) != 0 and f[i]:
        for j in true:
            f[j] = 1
            ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
s=[]
for i in range(N):
  A.append(int(input()))
  for j in range(A[i]):
    s.append(input().split())

s=sorted(s)
num=0 #num of lier
for k in range(len(s)):
  if N==2:
    if k>0:
      if s[k][1:]==0 or s[k-1][1:]:
        num=num+1 
  elif N>2:
    if s[k][:1]==s[k-1][:1] and s[k][1:]!=s[k-1][1:] and k>0:
      num=num+1
   
print(N-num)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    # input = sys.stdin.readline
    N = int(input())

    test = [dict() for _ in range(N)]

    count = 0

    for i in range(N):
        M = int(input())
        if M == 0:
            count += 1
        for _ in range(M):
            j, b = map(int, input().split())
            test[i][j-1] = bool(b)
            
    base_set = set(list(range(N)))

    for i in range(N):  # iが正直者と仮定
        honest = set()
        honest.add(i)
        lier = set()
        for j, b in test[i].items():  # 正直者の証言を作成
            if b:
                honest.add(j)
                for g, r in test[j].items():
                    if r:
                        honest.add(g)
                    else:
                        lier.add(g)
            else:
                lier.add(j)
        candidate = len(honest)
        for j in honest:  # 検証
            for g, r in test[j].items():
                if r:
                    if g in lier:
                        candidate = 0
                if not r:
                    if g in honest:
                        candidate = 0
                        
        count = max(count, candidate)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

carray = []

for Ai in Harray:
    honest = [Ai]
    c = 1
    for ans in Ai:
        que = []
        if ans[1] == 1:
            c += 1
            honest.append(Harray[ans[0]-1])
            que.append(ans[0]-1)
        while len(que) > 0:
            d = que[0]

            que.pop(0)
            
            e = 0
            for h in honest:
                for h2 in h:
                    if h2[1] == 1:
                        h3 = [h2[0], 0]
                    else:
                        h3 = [h2[0], 1]
                    if h3 in Harray[d]:
                        e = 1
            
            if e == 0:
                for ans2 in Harray[d]:
                    if (ans2[1] == 1) and (ans2[0] not in honest):
                        c += 1
                        que.append(ans2[0]-1)
            else:
                honest = []
                break
                    
    carray.append(len(honest))

print(max(carray))

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline
N = int(input())
memo = [[1] * N for _ in range(N)]
count = 0
for i in range(N):
    for j in range(int(input())):
        pos, flg = map(int, input().split())
        memo[pos - 1][i]= flg
for i in range(N):
    if min(memo[i]) == 1:
        count += 1
if count == 0:
    count += 1
print(count)

Submission status: Wrong Answer

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

ans = 0
for i in range(n):
  for j in range(a[i]):
    for k in range(i+1,n):
      for l in range(a[k]):
        # 互いを確認できる場合
        #print(i,j,k)
        #print(x[i][j][0], x[k][l][0])
        if x[i][j][0] == k+1 and i+1 == x[k][l][0] and x[i][j][1] == x[k][l][1] == 1 :
          ans += 2
        elif x[i][j][0] == k+1 and i+1 == x[k][l][0] and x[i][j][1] == x[k][l][1] == 0:
          ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
total_test = int(input())
res = list()
trick_p = 0
for test in range(total_test):
	pres = list()
	total_people = int(input())
	trick_p = total_people
	for person in range(total_people):
		p, r = map(int, input().split())
		pres.append(r)
	validate = pres.count(1) - pres.count(0)	
	res.append(True) if validate >= 1 else res.append(False)
# print(1 if res.count(True) == 0 and trick_p == 1 else res.count(True))
print(res.count(True))

Submission status: Wrong Answer

Solution code:
N = int(input())
mat = []
for i in range(N):
    A = int(input())
    tmp = [list(map(int,input().split())) for _ in range(A)]
    mat.append(tmp)
ans = N
num = list(range(1,N+1))
flag = [[[] for _ in range(2)] for _ in range(N)]
dic = dict(zip(num,flag))
count = 1
for i in mat:
    for j in range(len(i)):
        dic[i[j][0]][0].append(count)
        dic[i[j][0]][1].append(i[j][1])
    count += 1
tmp = list(dic.values())
pres = []
for i in range(len(tmp)):
    if tmp[i][0] == []:
        pres.append(i+1)
for i in range(len(pres)):
    for j in range(len(tmp)):
        for k in range(len(tmp[j][0])):
            if tmp[j][0][k] == pres[i] and tmp[j][1][k] == 0:
                tmp[j][1][k] = 1
                ans += -1
for i in range(len(tmp)):
    if 0 in tmp[i][1] and 1 in tmp[i][1]:
        ans += -1
for i in range(len(tmp)):
    if 1 in tmp[i][1] or tmp[i][1] == []:
        break
    else:
        if i == len(tmp)-1:
            ans += -1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())

T=0
F=0
for i in range(N):
  A=int(input())
  for j in range(A):
    x,y = map(int,input().split())
    if(y == 0):
      F+=1
    elif(y ==1):
      T+=1
             
if(T == F ):
  print("0")
elif(T>F):
  print(str(T))
elif(T < F):
  print(str(int(math.ceil(F/2))))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = []
for _ in range(n):
    a = int(input())
    d = []
    for _ in range(a):
        x = input().split()
        x = [int(i) for i in x]
        d.extend(x)
    data.append(d)

res = 0
for i in range(n):
    for j in range(0, int(len(data[i])), 2):
        dij = data[i][j]
        if data[i][j+1] == 1:
            if i+1 in data[dij-1][::2]:
                k = data[dij-1][::2].index(i+1)
                if data[dij-1][1::2][k] == 1:
                    res += 2
        elif data[i][j+1] == 0:
            if i+1 in data[dij-1][::2]:
                k = data[dij-1][::2].index(i+1)
                if data[dij-1][1::2][k] == 0:
                    res += 1

print(int(res/2))

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest as zi
n=int(input())
hil=[ [ [],[] ] for i in range(n)]
for i in range(n):
  hint=int(input())
  if hint:
    for j in range(hint):
      a,s=map(int,input().split())   
      hil[a-1][s]+=[i]

ans=0
for i in range(2**n)[::-1]:
  ss=bin(i)[2:]
  s="0"*(n-len(ss))+ss
  sset=set([fg for fg in range(n) if s[fg]=="1"])
  jjj,kkk=set(),set()
  for kk in sset:
    j,k=hil[kk]
    j,k=set(j),set(k)
    jjj|=j;kkk|=k
  if len(jjj&sset) or len(jjj&(kkk-sset)):
      break
  else:
    ans=max(ans,len(ss.replace("0","")))
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

sei={}
uso={}

ninzu=0
for j in range(1,n+1):
    i=int(input())
    sei[j]=set([j])
    uso[j]=set([])
    for _ in range(i):
        x,y=map(int,input().split())
        if y==1:
            sei[j].add(x)
        else:
            uso[j].add(x)

#print(sei)
#print(uso)

def saikiSei(k):
    temp=sei[k]
    for item in temp:
        if item not in saiki_sei:
            saiki_sei.add(item)
            saikiSei(item)
    return


cnt=0
for i in range(1,n+1):
    saiki_sei=set([])
    saiki_uso=set([0])
    saikiSei(i)
    #print("sei",saiki_sei)
    for item in saiki_sei:
        saiki_uso=saiki_uso|uso[item]
    #print("uso",saiki_uso)

    if saiki_sei.isdisjoint(saiki_uso):
        cnt=max(cnt,max(1,len(saiki_sei)))

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())#人数
check_lst = [[None for _ in range(N)] for _ in range(N)]

for i in range(N):
    A = int(input())

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



checker = [None for _ in range(N)]#i番目の人は正直者か
for i in range(N):
    for j in range(N):

        if check_lst[i][j] != 0 and check_lst[i][j] != 1:#評価がない場合
            pass

        else:#評価がある場合
            if check_lst[i][j] == 1: #iのjに対する評価が１のとき
                if check_lst[i][j] == check_lst[j][i]:
                    pass
                else:
                    checker[i] = False
                    break

            else:#iのjに対する評価が0のとき
                if checker[j] == True:#jが正直者と確定しているならば
                    checker[i] = False
                    break

                else:
                    pass

        
        if j == N-1:
            checker[i] = True

        
ans = 0
for e in checker:
    ans += int(True==e)

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from sys import stdin


def main():
    # コンソール入力を受け取る
    N = stdin.readline().rstrip()
    A_list = []
    X = []
    Y = []
    for n in range(int(N)):
        A = stdin.readline().rstrip()
        A_list.append(int(A))
        x_tmp = []
        y_tmp = []
        for a in range(int(A)):
            x, y = stdin.readline().rstrip().split()
            x_tmp.append(int(x))
            y_tmp.append(int(y))
        X.append(x_tmp)
        Y.append(y_tmp)

    flag = []
    for i in range(int(N)):
        flag.append(-1)

    tmp = 0
    for i in range(len(Y)):
        if not all([x == 0 for x in Y[i]]):
            tmp = 1
            break

    if tmp ==1:
        count = 0
        for i in range(len(X)):
            for j in range(len(X[i])):
                if flag[X[i][j] - 1] == -1:
                    flag[X[i][j] - 1] = Y[i][j]
                elif flag[X[i][j] - 1] == 0 and Y[i][j] == 1:
                    count += 1
                elif flag[X[i][j] - 1] == 1 and Y[i][j] == 0:
                    count += 1
        print(int(N) - count)
    else:
        print(1)


if __name__ == '__main__':
    main()