#include <bits/stdc++.h>
using namespace std;
const long long MXN = 5e5 + 10;
const long long INF = 1e18;
long long n, rt, ans;
long long A[MXN], lg[MXN];
vector<long long> adj[MXN], Jads;
long long W(long long u, long long v, long long k) {
  return A[u] + A[v] + min(A[u], A[v]) * k;
}
void dfs(long long u, long long par, long long h) {
  long long now = W(u, rt, lg[h]);
  for (int i = 0; (1LL << i) <= h; i++) {
    now = min(now, W(u, Jads[h - (1LL << i)], i));
  }
  ans += now * (u != rt);
  Jads.push_back(u);
  for (auto v : adj[u]) {
    if (v != par) dfs(v, u, h + 1);
  }
  Jads.pop_back();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  lg[1] = 0;
  long long f;
  for (f = 1; (1LL << f) < MXN; f++) lg[(1LL << f)] = f;
  lg[MXN - 1] = f;
  for (int i = MXN - 1; i > 1; i--) lg[i] = (!lg[i] ? lg[i + 1] : lg[i]);
  cin >> n, A[0] = INF;
  for (int i = 1; i <= n; i++) cin >> A[i], rt = (A[i] < A[rt] ? i : rt);
  for (int i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  dfs(rt, 0, 0);
  cout << ans << '\n';
  return 0;
}
