Problem p02925 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
vs = n * (n - 1) // 2

vmap = {}
c = 0
for i in range(n):
    for j in range(i):
        vmap[(i, j)] = c
        vmap[(j, i)] = c
        c += 1

edges = [[] for _ in range(vs)]
numin = [0] * vs
for i in range(n):
    for j in range(n - 2):
        j1 = a[i][j] - 1
        j2 = a[i][j + 1] - 1
        edges[vmap[(i, j1)]].append(vmap[(i, j2)])
        numin[vmap[(i, j2)]] += 1

order = []
day = [1] * vs
q = [i for i in range(vs) if numin[i] == 0]
while len(q) > 0:
    index = q.pop(0)
    order.append(index)
    d = day[index]
    for i in edges[index]:
        numin[i] -= 1
        if numin[i] == 0:
            q.append(i)
            day[i] = max(day[i], d + 1)

print(max(day) if len(order) == vs else -1)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

test_case = []
for x in (-1, 0, 1):
    for y in (-1, 0, 1):
        test_case.append((x, y))
for i in range(n):
    x1, y1 = xy[i]
    test_case.append((x1, y1))
    test_case.append((-x1, -y1))
    test_case.append((y1, -x1))
    test_case.append((-y1, x1))

ret = 0
for x1, y1 in test_case:
    sx, sy, tx, ty = 0, 0, 0, 0
    for j in range(n):
        x2, y2 = xy[j]
        if x1 * x2 + y1 * y2 > 0 or (x1 * x2 + y1 * y2 == 0 and -y1 * x2 + x1 * y2 >= 0):
            sx += x2
            sy += y2
        else:
            tx += x2
            ty += y2
    ret = max(ret, math.hypot(sx, sy), math.hypot(tx, ty))
print(ret)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
vs = n * (n - 1) // 2

vmap = {}
c = 0
for i in range(n):
    for j in range(i):
        vmap[(i, j)] = c
        vmap[(j, i)] = c
        c += 1

edges = [[] for _ in range(vs)]
numin = [0] * vs
for i in range(n):
    for j in range(n - 2):
        j1 = a[i][j] - 1
	j2 = a[i][j + 1] - 1
	edges[vmap[(i, j1)]].append(vmap[(i, j2)])
	numin[vmap[(i, j2)]] += 1

order = []
day = [1] * vs
q = [i for i in range(vs) if numin[i] == 0]
while len(q) > 0:
    index = q.pop(0)
    order.append(index)
    d = day[index]
    for i in edges[index]:
	numin[i] -= 1
	if numin[i] == 0:
            q.append(i)
            day[i] = max(day[i], d + 1)

print(max(day) if len(order) == vs else -1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(500000)

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
vs = n * (n - 1) // 2

vmap = {}
c = 0
for i in range(n):
    for j in range(i):
        vmap[(i, j)] = c
        vmap[(j, i)] = c
        c += 1

edges = [[] for _ in range(vs)]
numin = [0] * vs
for i in range(n):
    for j in range(n - 2):
        j1 = a[i][j] - 1
	j2 = a[i][j + 1] - 1
	edges[vmap[(i, j1)]].append(vmap[(i, j2)])
	numin[vmap[(i, j2)]] += 1

order = []
day = [1] * vs
q = [i for i in range(vs) if numin[i] == 0]
while len(q) > 0:
    index = q.pop(0)
    order.append(index)
    d = day[index]
    for i in edges[index]:
	numin[i] -= 1
	if numin[i] == 0:
            q.append(i)
            day[i] = max(day[i], d + 1)

print(max(day) if len(order) == vs else -1)