Problem p03166 (python)

Fixed submission:
import numpy as np
import sys
sys.setrecursionlimit(100000)
N,M=map(int,input().split())
d=[[] for i in range(N)]
for i in range(M):
    x,y=map(int,input().split())
    d[x-1].append(y-1)
dp=[0 for i in range(N)]

def depth(now,score,d):
    global dp
    if dp[now]==0 or not(dp[now]):
        if d[now]:
            _score=[]
            for i in d[now]:
                _score.append(depth(i,score+1,d)-score)
            dp[now]=max(_score)
        else:
            return score

        return dp[now]+score

    else:
        return dp[now]+score



Max=0
for i in range(N):
    m=depth(i,0,d)
    if  m>Max:            
        Max=m
print(Max)

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

N,M=map(int,input().split())
d=[[] for i in range(N)]
for i in range(M):
    x,y=map(int,input().split())
    d[x-1].append(y-1)
dp=[0 for i in range(N)]

def depth(now,score,d):
    global dp
    if dp[now]==0 or not(dp[now]):
        if d[now]:
            _score=[]
            for i in d[now]:
                _score.append(depth(i,score+1,d)-score)
            dp[now]=max(_score)
        else:
            return score

        return dp[now]+score

    else:
        return dp[now]+score



Max=0
for i in range(N):
    m=depth(i,0,d)
    if  m>Max:            
        Max=m
print(Max)

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

def depth(now,score):
    global scores,stamp,dp
    stamp.append(now)
    if d[now]:
        for i in d[now]:
             if dp[i]==0 or not(dp[i]):
                dp[i]=depth(i,score+1)
             else :
                 scores.append(score+dp[i])
    else:
        scores.append(score)
        return score


Max=0
for i in range(N):
    if not(i in stamp):
        depth(i,0)
        dp[i]=max(scores)
        if scores and dp[i]>Max:
            Max=max(scores)
        scores=[]
print(Max)

Buggy submission (verdict: Runtime Error):
scores=[]
stamp=[]
def depth(now,score,d):
    global scores,stamp
    stamp.append(now)
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
        return 
    else:
        scores.append(score)
        return 


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

Max=0
for i in range(N):
    if not(i in stamp):
        depth(i,0,d)
        if scores and max(scores)>Max:
            Max=max(scores)
        scores=[]
print(Max)

Buggy submission (verdict: Runtime Error):
scores=[]
def depth(now,score,d):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
        return 
    else:
        scores.append(score)
        return 


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

Max=0
for i in range(N):
    depth(i,0,d)
    if scores and max(scores)>Max:
        Max=max(scores)
    scores=[]
print(Max)

Buggy submission (verdict: Runtime Error):
scores=[]
def depth(now,score,d):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
    else:
        scores.append(score)
        return 


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

Max=0
for i in range(N):
    depth(i,0,d)
    if scores and max(scores)>Max:
        Max=max(scores)
    scores=[]
print(Max)

Buggy submission (verdict: Runtime Error):
scores=[]
def depth(now,score,d):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
    else:
        scores.append(score)


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

Max=0
for i in range(N):
    depth(i,0,d)
    if scores and max(scores)>Max:
        Max=max(scores)
    scores=[]
print(Max)

Buggy submission (verdict: Runtime Error):
scores=[]
def depth(now,score,d):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1,d)
    else:
        scores.append(score)


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

Max=0
for i in range(N):
    depth(i,0,d)
    if scores and max(scores)>Max:
        Max=max(scores)
    scores.clear()
print(Max)

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

scores=[]
def depth(now,score):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1)
    else:
        scores.append(score)
Max=0
for i in range(N):
    depth(i,0)
    if max(scores)>Max:
        Max=max(scores)
    scores.clear()
print(Max)

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

scores=[]
def depth(now,score):
    global scores
    if d[now]:
        for i in d[now]:
            depth(i,score+1)
    else:
        scores.append(score)
Max=0
for i in range(N):
    depth(i,0)
    if max(scores)>Max:
        Max=max(scores)
    scores.clear()
print(Max)