Problem p02837 (python)

Fixed submission:
import sys
# import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for j in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x-1, y))

# xy = np.array(xy)
# x, y = xy[:, :].T
# x = x.T 
# y = y.T

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        ok = True
        for i in range(n):
            if not comb >> i & 1:
                continue
            for x, y in xy[i]:
                if comb >> x & 1 ^ y:
                    ok = False
                    break
            if ok:
                cnt += 1
            else:
                break
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np 

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

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

if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

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

def main():

    res = np.full(2 ** n, 1, np.int64).reshape(-1, 1)
    comb = np.arange(2 ** n).reshape(-1, 1)
    for i in range(n):
        for x, y in xy[i]:
            bl = (comb >> i & 1) ^ (comb >> x & 1 ^ y)
            res &= bl
    
    cand = np.where(res == 1)[0]
    if not cand:
        return 0

    ans = np.amax(np.sum(cand.reshape(-1, 1) >> np.arange(n) & 1, axis=1))
    return ans    
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
x = []
y = []
for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    xi, yi = np.array([sys.stdin.readline().split() for _ in range(a)], dtype=np.int64).T
    x.append(xi)
    y.append(yi)

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if not comb >> i & 1:
                continue
            if np.any(comb >> (x[i] - 1) & 1 ^ y[i]):
                break
            cnt += 1
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

n = int(sys.stdin.readline().rstrip())
xy = [[] for _ in range(n)]

for i in range(n):
    a = int(sys.stdin.readline().rstrip())
    for j in range(a):
        x, y = map(int, sys.stdin.readline().split())
        xy[i].append((x-1, y))
xy = np.array(xy)
x, y = xy[:, :].T
x = x.T 
y = y.T

def main():
    ans = 0
    for comb in range(2 ** n):
        cnt = 0
        for i in range(n):
            if not comb >> i & 1:
                continue
            if np.any(comb >> x[i] & 1 ^ y[i]):
                break
            cnt += 1
        else:
            ans = max(ans, cnt)
    return ans
                
if __name__ == '__main__':
    ans = main()
    print(ans)