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

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

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if len(dp)==0 or A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)




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

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

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if len(dp)==0 or A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)

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

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

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)




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

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

Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u,v = map(int,input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)

visited = [False]*N
visited[0] = True
answer = [1]*N

def dfs(v, dp):
    for nv in Edge[v]:
        if visited[nv]:
            continue
        
        visited[nv] = True
        if len(dp)==0 or A[nv]>dp[-1]:
            dp.append(A[nv])
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp.pop()
        else:
            idx = bisect.bisect_left(dp, A[nv])
            temp = dp[idx]
            dp[idx] = A[nv]
            answer[nv] = len(dp)
            dfs(nv, dp)
            dp[idx] = temp
        
    return 

dfs(0, [A[0]])
answer[0] = 1
for a in answer:
    print(a)