Buggy python submission (verdict: Runtime Error):
import collections

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.collections.popleft()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)


Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.popleft()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())
L = [[False for j in range(N)] for i in range(N)]

for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    L[a][b] = True

dp = [0 for i in range(N)]

for i in range(N) :
    q = collections.deque()
    q.append(i)
    dist = [0 for i in range(N)]
    while q :
        now = q.pop()
        for j in range(N) :
            if not L[now][j] :
                continue
            dist[j] = max(dist[j], dist[now]+1)
            if j < i :
                dp[i] = max(dp[i], dist[j] + dp[j])
            else :
                q.append(j)
    dp[i] = max(dp[i], max(dist))

ans = max(dp)
print(ans)

    

Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())
L = [[False for j in range(N)] for i in range(N)]

for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    L[a][b] = True

dp = [0 for i in range(N)]

for i in range(N) :
    q = collections.deque()
    q.append(i)
    dist = [0 for i in range(N)]
    while q :
        now = q.pop()
        for j in range(N) :
            if not L[now][j] :
                continue
            dist[j] = max(dist[j], dist[now]+1)
            if j < i :
                dp[i] = max(dp[i], dist[j] + dp[j])
            else :
                q.append(j)
    dp[i] = max(dp[i], max(dist))

ans = max(dp)
print(ans)

    

Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())

path = [[False for i in range(N)] for j in range(N)]

not_start = []

for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    not_start.append(b)

not_start = set(not_start)

start = list(set(range(N)).difference(not_start))

ans = 0

for i in range(len(start)) :
    q = collections.deque()
    q.append(start[i])
    dist = [0 for i in range(N)]
    
    while q :
        now = q.pop()
        for j in range(N) :
            if path[now][j] :
                q.append(j)
                dist[j] = max(dist[j], dist[now]+1)
    
    ans = max(ans, max(dist))

print(ans)



Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())

path = [[False for i in range(N)] for j in range(N)]
detect_start = [[False for i in range(N)] for j in range(N)]
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    detect_start[b][a] = True

start = []
for i in range(N) :
    if not sum(detect_start[i]) :
        start.append(i)

ans = 0

for i in range(len(start)) :
    q = collections.deque()
    q.append(start[i])
    dist = [0 for i in range(N)]
    
    while q :
        now = q.pop()
        for j in range(N) :
            if path[now][j] :
                q.append(j)
                dist[j] = max(dist[j], dist[now]+1)
    
    ans = max(ans, max(dist))

print(ans)


Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())

path = [[False for i in range(N)] for j in range(N)]
detect_start = [[False for i in range(N)] for j in range(N)]
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    detect_start[b][a] = True

start = []
for i in range(N) :
    for j in range(N) :
        if detect_start[i][j] :
            break
    else :
        start.append(i)

ans = 0

for i in range(len(start)) :
    q = collections.deque()
    q.append(start[i])
    dist = [0 for i in range(N)]
    
    while q :
        now = q.popleft()
        for j in range(N) :
            if path[now][j] :
                q.append(j)
                dist[j] = max(dist[j], dist[now]+1)
    
    ans = max(ans, max(dist))

print(ans)


Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N,M = map(int,input().split())

path = [[False for i in range(N)] for j in range(N)]
detect_start = [[False for i in range(N)] for j in range(N)]
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    detect_start[b][a] = True

start = []
for i in range(N) :
    for j in range(N) :
        if detect_start[i][j] :
            break
    else :
        start.append(i)

ans = 0

for i in range(len(start)) :
    q = collections.deque()
    q.append(start[i])
    dist = [0 for i in range(N)]
    
    while q :
        now = q.pop()
        for j in range(N) :
            if path[now][j] :
                q.append(j)
                dist[j] = max(dist[j], dist[now]+1)
    
    ans = max(ans, max(dist))

print(ans)



Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)