Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
XY = [[] for i in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)


Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

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

dp = [-1 for i in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
XY = [[] for i in range(N)]
for i in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)
print(XY)

dp = [-1 for i in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
        
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)






Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
XY = []
for i in range(M):
    xy = list(map(int,input().split()))
    XY.append(xy)
p = [i+1 for i in range(N)]
ans = []
stack = []
alr = []
xy1 = []
for xy in XY:
    xy1.append(xy[1])
for i in range(1,N+1):
    if i not in xy1:
        stack.append(i)
        alr.append(i)

while len(stack) > 0:
    p1 = stack.pop(-1)
    flag = True
    for xy in XY:
        if p1 == xy[0]:
            alr.append(xy[1])
            stack.append(xy[1])
        if (p1 == xy[1]) and (xy[0] not in ans):
            flag = False
    if flag:
        ans.append(p1)

    
dp = [0 for i in range(len(ans))]

for i in range(len(ans)):
    for j in range(i):
        if [ans[j],ans[i]] in XY:
            dp[i] = max(dp[i],dp[j]+1)


print(max(dp))        


Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
XY = []
for i in range(M):
    xy = list(map(int,input().split()))
    XY.append(xy)
p = [i+1 for i in range(N)]
ans = []

while len(p) >= 1:
    for i in p:
        flag = True
        for xy in XY:
            if i == xy[1] and xy[0] not in ans:
                flag = False
        if flag:
            ans.append(i)
            p.remove(i)

dp = [0 for i in range(len(ans))]

for i in range(len(ans)):
    for j in range(i):
        if [ans[j],ans[i]] in XY:
            dp[i] = max(dp[i],dp[j]+1)


print(max(dp))        


Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
XY = []
for i in range(M):
    xy = list(map(int,input().split()))
    XY.append(xy)
p = [i+1 for i in range(N)]
ans = []

while len(p) >= 1:
    for i in p:
        flag = True
        for xy in XY:
            if i == xy[1] and xy[0] not in ans:
                flag = False
        if flag:
            ans.append(i)
            p.remove(i)

dp = [0 for i in range(len(ans))]

for i in range(len(ans)):
    for j in range(i):
        if [ans[j],ans[i]] in XY:
            dp[i] = max(dp[i],dp[j]+1)


print(max(dp))        


Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,M = map(int,input().split())
XY = [[] for m in range(N)]
for l in range(M):
    x,y = map(int,input().split())
    XY[x-1].append(y-1)

dp = [-1 for k in range(N)]
def search(i):
    if dp[i] != -1:
        return dp[i]
    c = 0
    start = XY[i]
    for s in start:
        c = max(c,search(s)+1)
    dp[i] = c
    return dp[i]

a = 0
for i in range(N):
    a = max(a,search(i))
print(a)