Problem p02698 (python)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**8)


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_-1].append(to-1)
    edges[to-1].append(from_-1)


DP = [10**9+7] * (n+1)
DP[0] = 0
ans = [0] * n


def dfs(node):
    node = node
    num = A[node]
    update_idx = bisect.bisect_left(DP, num)
    prev = DP[update_idx]
    DP[update_idx] = num
    lis = bisect.bisect_left(DP, 10**9+1) - 1
    ans[node] = lis
    for nex in edges[node]:
        if not ans[nex]:
            dfs(nex)

    DP[update_idx] = prev


dfs(0)
for res in ans:
    print(res)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**8)


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_-1].append(to-1)
    edges[to-1].append(from_-1)


DP = [10**9+7] * n
DP[0] = 0
ans = [0] * n


def dfs(node):
    node = node
    num = A[node]
    update_idx = bisect.bisect_left(DP, num)
    prev = DP[update_idx]
    DP[update_idx] = num
    lis = bisect.bisect_left(DP, 10**9+1) - 1
    ans[node] = lis
    for to in edges[node]:
        if not ans[to]:
            dfs(to)

    DP[update_idx] = prev


dfs(0)
for res in ans:
    print(res)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**8)


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_-1].append(to-1)
    edges[to-1].append(from_-1)


DP = [10**9+7] * n
DP[0] = 0
ans = [0] * n


def dfs(node):
    node = node
    num = A[node]
    update_idx = bisect.bisect_left(DP, num)
    prev = DP[update_idx]
    DP[update_idx] = num
    lis = bisect.bisect_left(DP, 10**9+1) - 1
    ans[node] = lis
    for to in edges[node]:
        if not ans[to]:
            dfs(to)

    DP[update_idx] = prev


dfs(0)
for res in ans:
    print(res)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**7)


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_-1].append(to-1)
    edges[to-1].append(from_-1)


DP = [10**9+7] * n
DP[0] = 0
ans = [0] * n


def dfs(node):
    node = node
    num = A[node]
    lis = bisect.bisect_left(DP, num)

    prev = DP[lis]
    ans[node] = lis
    DP[lis] = num
    for to in edges[node]:
        if not ans[to]:
            dfs(to)

    DP[lis] = prev


dfs(0)
for res in ans:
    print(res)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**6)


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_-1].append(to-1)
    edges[to-1].append(from_-1)


DP = [10**6] * n
DP[0] = 0
ans = [0] * n


def dfs(node):
    node = node
    num = A[node]
    lis = bisect.bisect_left(DP, num)

    prev = DP[lis]
    update = lis
    ans[node] = update
    DP[lis] = num
    for to in edges[node]:
        if not ans[to]:
            dfs(to)

    DP[lis] = prev


dfs(0)
for res in ans:
    print(res)