#include <bits/stdc++.h>
using namespace std;

//function to calculate the points collected in the path
int dfs(int x, vector<vector<int>> &arr, vector<bool> &vis, vector<int> &weight){
	int points_max = 0 ; 
	int points = 0 ; 
	vis[x] = true ;
	
	for(auto &i: arr[x]){
		if(!vis[i]){
			points = dfs(i, arr, vis, weight) ;
		}
		points_max = max(points_max, points) ; 
	}

	return weight[x] + points_max ; 
}

int main() {
	
	// input starts
	
	int N ; 
	cin >> N ; 
	
	vector<vector<int>> arr(N + 1) ;
	
	vector<bool> vis(N + 1, false) ;
	
	vector<int> weight(N + 1) ; 
	
	vector<int> ans ; 
	
	for(int i = 1; i <= N; ++i)cin >> weight[i] ;
	
	int u, v;
	
	for(int i = 0; i < N - 1; ++i){
		cin >> u >> v ;
		arr[u].push_back(v) ;
		arr[v].push_back(u) ;
	}
	
	// input ends here
	
	vis[1] = true ;
	
	for(auto &x: arr[1]){
		ans.push_back(dfs(x, arr, vis, weight)) ;
	}
	
	sort(ans.begin(), ans.end(), greater<int>()) ; 
	
	
	// if only 1 node & 0 edges
	if(ans.size() == 0){
		cout << weight[1] ; 
	}
	// if only 2 node nodes & 1 edge
	else if(ans.size() == 1){
		cout << weight[1] + ans[0] ; 
	}
	else{
		cout << ans[0] + ans[1] + weight[1] ;
	}
	
	return 0;
}