#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int n;
int a[500011];
int mn[500011][20], m[500011][20];
int pa[500011][20];
int root;
vector<int> adj[500011];
long long ans;
inline void add(int u) {
  long long res = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = 0; i < 20; i++) {
    smin(res, (long long)mn[u][i] * (i + 1) + a[u]);
  }
  ans += res;
}
void dfs(int u, int fa = 0) {
  pa[u][0] = fa;
  mn[u][0] = a[fa];
  m[u][0] = a[u];
  for (int i = 1; i < 20; i++) {
    pa[u][i] = pa[pa[u][i - 1]][i - 1];
    m[u][i] = min(m[u][i - 1], m[pa[u][i - 1]][i - 1]);
    mn[u][i] = m[pa[pa[u][i - 1]][0]][i - 1];
  }
  if (fa) add(u);
  for (int i = 0; i < ((int)adj[u].size()); i++) {
    int v = adj[u][i];
    if (v == fa) continue;
    dfs(v, u);
  }
}
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  root = 1;
  for (int i = 1; i <= n; i++)
    if (a[i] < a[root]) root = i;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  a[0] = 0x3f3f3f3f;
  for (int i = 0; i < 20; i++) m[0][i] = 0x3f3f3f3f;
  dfs(root);
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
