Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for j in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Buggy python submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(next) + 1 for next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for j in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
edges = [[0 for i in range(N)] for j in range(N+1)]
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x][y] = 1
for i in range(N):
    edges[N][i] = 1

memo_ls = [None for i in range(N+1)]
def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    cnt = max([dfs(next) + 1 if edges[last][next] != 0 else 0 for next in range(N)])
    memo_ls[last] = cnt
    return cnt
print(dfs(N) - 1)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for j in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
edges = [[0 for i in range(N)] for j in range(N+1)]
for i in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x][y] = 1
for i in range(N):
    edges[N][i] = 1

memo_ls = [None for i in range(N+1)]
def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    cnt = max([dfs(next) + 1 if edges[last][next] != 0 else 0 for next in range(N)])
    memo_ls[last] = cnt
    return cnt
print(dfs(N) - 1)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N, M = [int(i) for i in input().split()]
edges = {j : [] for j in range(N + 1)}
for j in range(M):
    x, y = [int(i) for i in input().split()]
    x -= 1
    y -= 1
    edges[x].append(y)
for i in range(N):
    edges[N].append(i)

memo_ls = [None for i in range(N + 1)]


def dfs(last):
    if memo_ls[last] is not None:
        return memo_ls[last]
    if len(edges[last]) == 0:
        return 0
    cnt = max([dfs(_next) + 1 for _next in edges[last]])
    memo_ls[last] = cnt
    return cnt


print(dfs(N) - 1)