Buggy python submission (verdict: Runtime Error):
import collections
n,m = map(int,input().split())
d = {}
indegree = [0]*n
for _ in range(m):
    x,y = map(int,input().split())
    d[x-1] = d.get(x-1,[]) + [y-1]
    indegree[y-1] += 1
dp = [0]
q = collections.deque([i for i in range(n) if indegree[i] == 0])
while q:
    node = q.popleft()
    for nei in d.get(node,[]):
        indegree[nei] -= 1
        dp[nei] = max(dp[nei],dp[node]+1)
        if indegree[nei] == 0:
            q.append(nei)
return max(dp)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
d = {}
for _ in range(m):
    x,y = map(int,input().split())
    d[x-1] = d.get(x-1,[]) + [y-1]
memo = {}
def dp(i):
    if i not in d:
        return 0
    if i not in memo:
        memo[i] = 0
        for nei in d.get(i,[]):
            memo[i] = max(memo[i],dp(nei)+1)
    return memo[i]
ans = 0
for i in range(n):
    ans = max(ans,dp(i))
print(ans)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
d = {}
for _ in range(m):
    x,y = map(int,input().split())
    d[x-1] = d.get(x-1,[]) + [y-1]
memo = {}
def dp(i):
    if i not in d:
        return 0
    if i not in memo:
        memo[i] = 0
        for nei in d[i]:
            memo[i] = max(memo[i],dp(nei)+1)
    return memo[i]
ans = 0
for i in range(n):
    ans = max(ans,dp(i))
print(ans)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
res ={}
for _ in range(m):
    x,y = map(int,input().split())
    res[x] = res.get(x,[]) + [y]
memo = {} #nodeを始点としたパスの最長長さ
def dfs(node):
    if node in memo:
        return memo[node]
    a = 0
    for n in res.get(node,[]):
        a = max(a,dfs(n)+1)
    memo[node] = a
    return memo[node]

ans = 0
for i in range(1,n+1):
    ans = max(ans,dfs(i))
print(ans)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
res ={}
for _ in range(m):
    x,y = map(int,input().split())
    res[x] = res.get(x,[]) + [y]
memo = {} #nodeを始点としたパスの最長長さ
def dfs(node):
    if node in memo:
        return memo[node]
    a = 0
    for n in res.get(node,[]):
        a = max(a,dfs(n)+1)
    memo[node] = a
    return memo[node]

ans = 0
for i in range(n):
    ans = max(ans,dfs(i))
print(ans)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
res ={}
for _ in range(m):
    x,y = input().split()
    res[x] = res.get(x,[]) + [y]
memo = {} #nodeを始点としたパスの最長長さ
def dfs(node):
    if node in memo:
        return memo[node]
    a = 0
    for n in res.get(node,[]):
        a = min(a,dfs(n)+1)
    memo[node] = a
    return memo[node]

ans = 0
for i in range(n):
    ans = max(ans,dfs(i))
return ans

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    adjL[x-1].append(y-1)
    indegs[y-1] += 1
 
dp = [0] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        dp[v2] = max(dp[v2], dp[vNow] + 1)
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)
 
print(max(dp))