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

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
memo = [-1]*N
dic = [[] for i in range(N)]
def dfs(dic, memo, v):
    if memo[v] != -1:
        return memo[v]
    plen = 0
    for i in dic[v]:
        plen = max(plen, dfs(dic, memo, i)+1)
    memo[v] = plen
    return plen
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
ans = 0
for i in range(N):
    ans = max(ans, dfs(dic, memo, i))
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
memo = [-1]*N
dic = [[] for i in range(N)]
def dfs(dic, memo, v):
    if memo[v] != -1:
        return memo[v]
    plen = 0
    for i in dic[v]:
        plen = max(plen, dfs(dic, memo, i)+1)
    memo[v] = plen
    return plen
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
ans = 0
for i in range(N):
    ans = max(ans, dfs(dic, memo, i))
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
memo = [-1]*N
def dfs(dic, p, memo):
    if memo[p] != -1:
        return memo[p]
    m = 0
    for d in dic[p]:
        m = max(m, dfs(dic, d, memo)+1)
    memo[p] = m
    return m
dic = [[] for i in range(N)]
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
ans = 0
for i in range(N):
    k= dfs(dic, i, memo)
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
def dfs(dic, p, memo):
    if memo[p] != -1:
        return memo[p]
    m = 0
    for d in dic[p]:
        m = max(m, dfs(dic, d, memo)+1)
    memo[p] = m
    return m
dic = [[] for i in range(N)]
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
inf = -1
memo = [inf]*N
ans = 0
for i in range(N):
    k= dfs(dic, i, memo)
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
def dfs(dic, p, memo):
    if memo[p] != -1:
        return memo[p]
    m = 0
    for d in dic[p]:
        m = max(m, dfs(dic, d, memo)+1)
    memo[p] = m
    return m
dic = [[] for i in range(N)]
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
inf = -1
memo = [inf]*N
ans = 0
for i in range(N):
    k= dfs(dic, i, memo)
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
def dfs(p):
    if memo[p] != -1:
        return memo[p]
    m = 0
    for d in dic[p]:
        m = max(m, dfs(d)+1)
    memo[p] = m
    return m
dic = [[] for i in range(N)]
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1].append(y-1)
    
inf = -1
memo = [inf]*N
ans = 0
for i in range(N):
    k= dfs(i)
    memo[i] = k
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
def make_graph(x, y, dic):
    if x in dic.keys():
        dic[x].append(y)
    else:
        dic[x] = [y]
def dfs(p):
    if memo[p] != -1:
        return memo[p]
    if p not in dic.keys():
        return 0
    m = 0
    for d in dic[p]:
        m = max(m, dfs(d)+1)
    return m
dic = {}
for m in range(M):
    x, y = map(int, input().split())
    make_graph(x-1, y-1, dic)
inf = -1
memo = [inf]*N
ans = 0
for i in range(N):
    k= dfs(i)
    memo[i] = k
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
def make_graph(x, y, dic):
    if x in dic.keys():
        dic[x].append(y)
    else:
        dic[x] = [y]
def dfs(p):
    if memo[p] != -1:
        return memo[p]
    if p not in dic.keys():
        return 0
    m = 0
    for d in dic[p]:
        m = max(m, dfs(d)+1)
    return m

dic = {}
for m in range(M):
    x, y = map(int, input().split())
    make_graph(x-1, y-1, dic)

inf = -1
memo = [inf]*N
ans = 0
for i in range(N):
    k= dfs(i-1)
    memo[i-1] = k
    ans = max(ans,k)
print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy
N, M = map(int, input().split())
dic = numpy.zeros([N,N], dtype = int)
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1][y-1] = 1
mat = numpy.matrix(dic, int)
memo = numpy.zeros([N+1, N], dtype = int)
memo[0] = 1
z = numpy.zeros([N], int)
ans = 0
for n in range(N):
    memo[n+1] = numpy.dot(mat,(memo[n].reshape(-1,1))).reshape(N)
    if memo[n+1].any() == 0:
        if ans == 0:
            ans = n
            print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy
N, M = map(int, input().split())
dic = numpy.zeros([N,N], dtype = int)
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1][y-1] = 1
mat = numpy.matrix(dic, int)
memo = numpy.zeros([N+1, N], dtype = int)
memo[0] = 1
z = numpy.zeros([N], int)
ans = 0
for n in range(N):
    memo[n+1] = numpy.dot(mat,(memo[n].reshape(-1,1))).reshape(N)
    if memo[n+1].any() == 0:
        if ans == 0:
          ans = n
          print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)

Buggy python submission (verdict: Runtime Error):
import numpy
N, M = map(int, input().split())
dic = numpy.zeros([N,N], dtype = int)
for m in range(M):
    x, y = map(int, input().split())
    dic[x-1][y-1] = 1
mat = numpy.matrix(dic, int)
memo = numpy.zeros([N+1, N], dtype = int)
memo[0] = 1
z = numpy.zeros([N], int)
for n in range(N):
    memo[n+1] = (mat@(memo[n].reshape(-1,1))).reshape(4)
    if memo[n+1].any() == 0:
        print(ans)

Fixed submission:
import sys
 
sys.setrecursionlimit(100000)
 
N, M = map(int, input().split(" "))
G = [[] for _ in range(N)]
 
for _ in range(M):
    x, y = map(int, input().split(" "))
    G[x-1].append(y-1)
dp = [-1] * N
def pathlen(G, dp, v):
    if dp[v] != -1:
        return dp[v]
 
    plen = 0
    for i in G[v]:
        plen = max(plen, pathlen(G, dp, i)+1)
    dp[v] = plen
    return plen
ans = 0
for i in range(N):
    ans = max(ans, pathlen(G, dp, i))
print(ans)