Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5 + 1)

N, M = map(int, input().split())
nodes = [[] for _ in range(N)]

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

dp = [-1] * N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    return edges

answer = 0  
for i in range(N):
  answer = max(answer, judge(i))
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5 + 1)
import numpy as np
N, M = map(int, input().split())
path = np.zeros((N+1, N+1), dtype=np.int64)
 
def judge(bool_array):
  for index, bool_value in enumerate(bool_array[1:], 1):
    if bool_value > path[index, 0]:
      # print('index={}, bool_value={}'.format(index, bool_value))
      plus_value = bool_value - path[index, 0]
      np.where(path[index, 1:] > 0, path[index, 1:]+plus_value, 0)
      path[index, 0] = bool_value
      judge(path[index, :1])

for _ in range(M):
  x, y = map(int, input().split())
  # print('x={}, y={}'.format(x, y))
  path[x, y] = path[x, 0] + 1
  bool_array = np.zeros(N+1, dtype=np.int64)
  bool_array[y] = path[x, y]
  judge(bool_array)
  # print(path)
print(path[:, 0].max())

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
nodes = [[] for _ in range(N)]

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

dp = [-1] * N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    return dp[index]

answer = 0  
for i in range(N):
  answer = max(answer, judge(i))
print(answer)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
nodes = [[] for _ in range(N)]

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

dp = [-1] * N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  else:
    edges = 0
    for i in nodes[index]:
      edges = max(edges, 1+judge(i))
    dp[index] = edges
    return dp[index]
    
for i in range(N):
  judge(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
nodes = [[] for _ in range(N)]

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

dp = [-1] * N

def judge(index):
  if dp[index] != -1:
    return dp[index]
  elif not nodes[index]:
    dp[index] = 0
    return 0
  else:
    dp[index] = max(1 + judge(i) for i in nodes[index])
    return dp[index]
    
for i in range(N):
  judge(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
path = np.zeros((N+1, N+1), dtype=np.int64)

def judge(bool_array):
  for index, bool_value in enumerate(bool_array[1:], 1):
    if bool_value > path[index, 0]:
      # print('index={}, bool_value={}'.format(index, bool_value))
      plus_value = bool_value - path[index, 0]
      np.where(path[index, 1:] > 0, path[index, 1:]+plus_value, 0)
      path[index, 0] = bool_value
      judge(path[index, :1])

for _ in range(M):
  x, y = map(int, input().split())
  # print('x={}, y={}'.format(x, y))
  path[x, y] = path[x, 0] + 1
  bool_array = np.zeros(N+1, dtype=np.int64)
  bool_array[y] = path[x, y]
  judge(bool_array)
  # print(path)
print(path[:, 0].max())