#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 512345;
vector<int> g[MAXN];
ll a[MAXN];
vector<int> path;
ll ans;
int n;
void dfs(int u, int p) {
  ll best = numeric_limits<ll>::max();
  ll L = 0;
  int last_d = 0;
  for (int d = 1; d <= path.size(); d *= 2) {
    last_d = d;
    int np = path[path.size() - d];
    ll sub = L * a[np] - a[p] + a[np];
    best = min(best, sub);
    L++;
  }
  if (last_d != path.size()) {
    int np = path[0];
    ll sub = L * a[np] - a[p] + a[np];
    best = min(best, sub);
  }
  if (best < 0) ans += best;
  path.push_back(u);
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
  }
  path.pop_back();
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int root = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < a[root]) root = i;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    ans += a[u] + a[v];
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(root, -1);
  cout << ans << endl;
}
