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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
ans = 0
dp = [1 for _ in range(N)]
zerolist = [0 for _ in range(N)]
while True:
	pnode = copy.copy(dp)
	dp = [0 for _ in range(N)]
	for i in range(N):
		if pnode[i] == 1 and i in t_table:
			for j in t_table[i]:
				if dp[j]==0 : dp[j]= 1
	if(dp == zerolist):
	 	print(ans)
	 	break
	ans += 1


Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
ans = 0
dp = [1 for _ in range(N)]
zerolist = [0 for _ in range(N)]
while True:
	pnode = dp.copy()
	dp = [0 for _ in range(N)]
	for i in range(N):
		if pnode[i] == 1 and i in t_table:
			for j in t_table[i]:
				if dp[j]==0 : dp[j]= 1
	if(dp == zerolist):
	 	print(ans)
	 	break
	ans += 1


Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
ans = 0
dp = [1 for _ in range(N)]
zerolist = [0 for _ in range(N)]
while True:
	pnode = dp.copy()
	dp = [0 for _ in range(N)]
	for i in range(N):
		if pnode[i] == 1 and i in t_table:
			for j in t_table[i]:
				if dp[j]==0 : dp[j]= 1
	if(dp == zerolist):
	 	print(ans)
	 	break
	ans += 1

Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
ans = 0
dp = np.ones(N, dtype='int32')
while True:
	pnode = dp.copy()
	dp = np.zeros(N, dtype='int32')
	for i in np.where(pnode)[0]:
		if i in t_table :
			dp[t_table[i]] += 1
	dp[dp>0] = 1
	if((dp == 0).all()):
	 	print(ans)
	 	break
	ans += 1

Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy as np

N,M = map(int, input().split())
t_table = {}
for i in range(M):
	x,y = map(int, input().split())
	if x-1 in t_table: t_table[x-1].append(y-1)
	else: t_table[x-1] = [y-1]
mem = np.zeros(N, dtype='int32')
ans = 0
ccheck = [True for _ in range(N)]
NodeList = np.array([i for i in range(N)])
while True:
	p_mem = mem.copy()
	p_cnt = np.zeros(N, dtype='int32')
	for i in NodeList[ccheck]:
		if i in t_table :
			p_cnt[t_table[i]] = 1
	mem+=p_cnt
	ccheck = (mem!=p_mem)
	if((mem==p_mem).all()):
	 	print(ans)
	 	break
	ans += 1

Fixed submission:
import sys

sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

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

dp = [-1] * N

def rec(v):
	if dp[v] != -1:
		return dp[v]
	ans = 0
	lst_nv = lst_edge[v]
	for nv in lst_nv:
		ans = max(ans, rec(nv)+1)
	dp[v] = ans
	return dp[v]

ans = 0
for v in range(N):
	ans = max(ans,rec(v))
print(ans)