#include <bits/stdc++.h>
#define MAXN 200010
#define MIX 200000000000000LL

using namespace std;

typedef  long long ll;

ll n;
ll a[MAXN];
bool obr[MAXN];
vector<ll> sus[MAXN];
ll rezU[MAXN]; // rez ako uzmemo i
ll rezNUS[MAXN]; // rez ako ne uzmemo i
ll rezNUNS[MAXN];

vector<ll> vU[MAXN];
vector<ll> vNUS[MAXN];
vector<ll> vNUNS[MAXN];

ll mini(ll a, ll b, ll c)
{
    return min(a, min(b, c));
}

void obradi(ll v)
{
    obr[v] = true;
    vector<ll> susV;
    for(auto u : sus[v])
    {
        if(!obr[u])
        {
            susV.push_back(u);
            obradi(u);
        }
    }
    ll brUz = 0;
    ll minD = LLONG_MAX;
    for(auto u : susV)
    {
        if(rezU[u] < rezNUS[u]) brUz++;
        rezU[v] += mini(rezNUS[u], rezNUNS[u], rezU[u]);
        rezNUS[v] += min(rezNUS[u], rezU[u]);
    }
    rezU[v] += a[v];
    if(brUz == 0)
    {
        for(auto u : susV)
        {
            rezNUS[v] += min(rezNUS[u], rezU[u]);
            minD = min(minD, rezU[u] - rezNUS[u]);
        }
        rezNUS[v] += minD;
    }
    if(susV.empty()) rezNUS[v] = MIX;
    if(susV.empty()) rezNUNS[v] = 0;
    if(susV.empty())
    {
        vU[v].push_back(v);
    }
    for(auto u : susV) rezNUNS[v] += rezNUS[u];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        sus[x].push_back(y);
        sus[y].push_back(x);
    }
    obradi(1);
    /**
    for(int i = 1; i <= n; i++)
    {
        cout << i << " " << rezU[i] << " " << rezNUS[i] << " " << rezNUNS[i] << "\n";
    }
    **/
    cout << min(rezNUS[1], rezU[1]);
    return 0;
}