#include <bits/stdc++.h>
#define pc pair<int, string>
#define ll long long

using namespace std;


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int n;cin>>n;
    ll a[n+5];
    for(int i = 0; i<n; i++)cin>>a[i];

    ll cnt = 0;
    vector< vector <int> > st(n+2);

    for(int i = 0; i<n-1; i++)
    {
        int a, b;cin>>a>>b;
        cnt+=(a==1);
        cnt+=(b==1);
        st[a].push_back(b);
        st[b].push_back(a);
    }

    if(cnt==n-1)
    {
        ll s = 0;
        for(int i = 1; i<n; i++)s+=a[i];
        cout<<min(a[0], s)<<"\n";
    }


    return 0;
}