Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(11000)
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)

Buggy submission (verdict: Runtime Error):
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)

Buggy submission (verdict: Runtime Error):
def util(adj, curr, dp):
    res = 0
    if dp[curr] != -1:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next, dp))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
dp = [-1]*n
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i, dp))
print(lp)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
 
dp = {}
def util(adj, curr):
    res = 0
    if curr in dp:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next))
    dp[curr] = res
    return res
 
n, m = map(int, input().strip().split())
adj = defaultdict(list)
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)
 
lp = 0
for i in range(n):
    lp = max(lp, util(adj, i))
print(lp)

Buggy submission (verdict: Runtime Error):
dp = {}
def util(adj, curr):
    if curr in dp:
        return dp[curr]
    res = 0
    for next in adj[curr]:
        res = max(res, 1 + util(adj, next))
    dp[curr] = res
    return res

n, m = map(int, input().split())
adj = {}
for _ in range(m):
    x, y = map(int, input().split())
    if x in adj:
        adj[x].append(y)
    else:
        adj[x] = [y]

lp = 0
for i in range(1, n + 1):
    lp = max(lp, util(adj, i))
print(lp)

Buggy submission (verdict: Runtime Error):
dp = {}
def util(adj, curr):
    if curr in dp:
        return dp[curr]
    res = 0
    for next in adj[curr]:
        res = max(res, 1 + util(adj, next))
    dp[curr] = res
    return res

n, m = map(int, input().strip().split())
adj = {}
for _ in range(m):
    x, y = map(int, input().strip().split())
    if x in adj:
        adj[x].append(y)
    else:
        adj[x] = [y]

lp = 0
for i in range(1, n + 1):
    lp = max(lp, util(adj, i))
print(lp)

Buggy submission (verdict: Runtime Error):
dp = {}
def util(adj, curr):
    if curr in dp:
        return dp[curr]
    res = 0
    for next in adj[curr]:
        res = max(res, 1 + util(adj, next))
    dp[curr] = res
    return res

n, m = map(int, input().strip().split())
adj = {}
for _ in range(m):
    x, y = map(int, input().strip().split())
    if x in adj:
        adj[x].append(y)
    else:
        adj[x] = [y]

lp = 0
for i in range(1, n + 1):
    lp = max(lp, util(adj, i))
print(lp)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

dp = {}
def util(adj, curr):
    res = 0
    if curr in dp:
        return dp[curr]
    for next in adj[curr]:
        res = max(res,1 + util(adj, next))
    dp[curr] = res
    return res

n, m = map(int, input().strip().split())
adj = defaultdict(list)
for _ in range(m):
    x, y = map(int, input().strip().split())
    adj[x - 1].append(y - 1)

lp = 0
for i in range(n):
    lp = max(lp, util(adj, i))
print(lp)