Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)
dp = [-1] * N
def solve(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for nn in E[n]:
        res = max(res, solve(nn)+1)
    dp[n] = res
    return dp[n]
ans = 0
for i in range(N):
    ans = max(ans, solve(i))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)
dp = [-1] * N
def solve(n):
    if dp[n] != -1:
        return dp[n]
    dp[n] = 0
    for nn in E[n]:
        dp[n] = max(dp[n], solve(nn)+1)
    return dp[n]
ans = 0
for i in range(N):
    ans = max(ans, solve(i))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [[] for i in range(N)]
for i in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)
dp = [-1] * N
def solve(n):
    if dp[n] != -1:
        return dp[n]
    dp[n] = 0
    for nn in E[n]:
        dp[n] = max(dp[n], solve(nn)+1)
    return dp[n]
ans = 0
for i in range(N):
    ans = max(ans, solve(i))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
E = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)
dp = [-1] * N
def solve(n):
    if dp[n] != -1:
        return dp[n]
    dp[n] = 0
    for nn in E[n]:
        dp[n] = max(dp[n], solve(nn)+1)
    return dp[n]
ans = 0
for i in range(N):
    ans = max(ans, solve(i))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
E = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    E[x].append(y)
dp = [-1] * N
def solve(n):
    if dp[n-1] != -1:
        return dp[n-1]
    dp[n-1] = 0
    for nn in E[n]:
        dp[n-1] = max(dp[n-1], solve(nn)+1)
    return dp[n-1]
ans = 0
for i in range(N):
    ans = max(ans, solve(i+1))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
N, M = map(int, input().split())
E = defaultdict(list)
for i in range(M):
    x, y = map(int, input().split())
    E[x].append(y)
dp = [-1] * N
def solve(n):
    global dp, E
    if dp[n-1] != -1:
        return dp[n-1]
    dp[n-1] = 0
    for nn in E[n]:
        dp[n-1] = max(dp[n-1], solve(nn)+1)
    return dp[n-1]
ans = 0
for i in range(N):
    ans = max(ans, solve(i+1))
print(ans)

Fixed submission:
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])