Buggy python submission (verdict: Runtime Error):
def get_nagasa(i):
    if nagasa[i] != -1:
        return nagasa[i]
    if ko[i] == []:
        nagasa[i] = 0
        return 0
    re = 0
    for ii in ko[i]:
        p = get_nagasa(ii) + 1
        if p > re:
            re = p
    nagasa[i] = re
    return re

n, m = map(int, input().split())
ko = [[] for _ in range(n)]
nagasa = [-1] * n
for _ in range(m):
    x, y = map(int, input().split())
    ko[x - 1] += [y - 1]
mx = 0
for i in range(n):
    tmp = get_nagasa(i)
    if tmp > mx:
        mx = tmp
print(mx)


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))

Buggy python submission (verdict: Runtime Error):
def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))

Buggy python submission (verdict: Runtime Error):
def get_kyori(i):
    if kos[i]==[]:
        return 0
    if kyori[i]!=-1:
        return kyori[i]
    re=0
    for ko in kos[i]:
        new=get_kyori(ko)+1
        if re<new:
            re=new
    kyori[i]=re
    return re

n,m=map(int,input().split())
kos=[[] for _ in range(n+1)]
kyori=[-1]*(n+1)
for _ in range(m):
    oya,ko=map(int,input().split())
    kos[oya]+=[ko]

ans=0
for i in range(1,n+1):
    if kyori[i]==-1:
        kyori[i]=get_kyori(i)
    if kyori[i]>ans:
        ans=kyori[i]

print(ans)

Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))

Buggy python submission (verdict: Runtime Error):
def get_kyori(i):
    if kos[i]==[]:
        return 0
    if kyori[i]!=-1:
        return kyori[i]
    re=0
    for ko in kos[i]:
        new=get_kyori(ko)+1
        if re<new:
            re=new
    kyori[i]=re
    return re

n,m=map(int,input().split())
kos=[[] for _ in range(n+1)]
kyori=[-1]*(n+1)
for _ in range(m):
    oya,ko=map(int,input().split())
    kos[oya]+=[ko]

for i in range(1,n+1):
    if kyori[i]==-1:
        kyori[i]=get_kyori(i)

print(max(kyori[1:]))

Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
h={}
st=set([i for i in range(1,n+1)])
kos=set()
for _ in range(m):
    oy,ko=map(int,input().split())
    h.setdefault(oy,[])
    h[oy]+=[ko]
    kos.add(ko)
st=st-kos
dep=0
while 1:
    nst=set()
    for s in st:
        if s not in h:continue
        for ko in h[s]:
            nst.add(ko)
    if len(nst)==0:
        break
    st=nst
    dep+=1
print(dep)

Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def get_kyori(i):
    if kos[i] == []:
        kyori[i] = 0
        return 0
    if kyori[i] > -1:
        return kyori[i]
    re = 0
    for ko in kos[i]:
        new = get_kyori(ko) + 1
        if re < new:
            re = new
    kyori[i] = re
    return re


n, m = map(int, input().split())
kos = [[] for _ in range(n + 1)]
kyori = [-1] * (n + 1)
for _ in range(m):
    oya, ko = map(int, input().split())
    kos[oya] += [ko]

for i in range(1, n + 1):
    if kyori[i] == -1:
        kyori[i] = get_kyori(i)

print(max(kyori[1:]))