Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem.get(v) is None
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = [0 for _ in range(n)]
d = 0


def has_edge(edges, v, g, d):
    target = edges.get(v)
    if target is not None and mem[v] == 0:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = {}
d = 0


def has_edge(edges, v, g, d):
    target = edges[v]
    if mem.get(v) is None:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = {i: int(input())-1 for i in range(n)}
mem = [0 for _ in range(n)]
d = 0


def has_edge(edges, v, g, d):
    target = edges[v]
    if mem[v] == 0:
        mem[v] = 1
        if target == g:
            return d
        else:
            return has_edge(edges, target, g, d+1)
    return -2


print(has_edge(edges, 0, 1, d)+1)


Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
edges = [[0 for _ in range(n)] for _ in range(n)]
mem = [[0 for _ in range(n)] for _ in range(n)]
dist = []

for i in range(n):
    edges[i][int(input())-1] = 1

def has_edge(edges, v, t, d):
    targets = [i for i, e in enumerate(edges[v]) if e != 0]
    for target in targets:
        if mem[v][target] == 0:
            mem[v][target] = 1
            if target == t:
                dist.append(d)
                return True
            else:
                return has_edge(edges, target, t, d+1)
    return False


print(min(dist)+1) if has_edge(edges, 0, 1, 0) else print(-1)

Fixed submission:
n = int(input())
edges = {i: int(input())-1 for i in range(n)}


def push_buttom(v, goal):
    for i in range(n):
        v = edges[v]
        if v == goal:
            return i+1
    return -1


print(push_buttom(0, 1))