Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [0] * n
for i in range(n - 1):
    for j in range(n):
        if graph[j] is not None:
            for k in graph[j]:
                dp[j] = max(dp[j], dp[k] + 1)
print(max(dp))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))