from collections import defaultdict import sys sys.setrecursionlimit(10**6) N = int(input()) S = list(map(int, input().split())) adj = defaultdict(list) degs = [0] * N for _ in range(N-1): a, b = map(lambda x: int(x)-1, input().split()) adj[a].append(b) adj[b].append(a) degs[a] += 1 degs[b] += 1 def dfs(v): s = S[v] res = s for to in adj[v]: if s >= S[to]: continue res = max(res, s + dfs(to)) return res ans = 0 for i in range(N): skip = False for to in adj[i]: if S[to] > S[i]: b = True if not skip: ans = max(ans, dfs(i)) print(ans)