#include <bits/stdc++.h>
using namespace std;
inline int read();
const int N = 5e5 + 5;
int n;
int v[N], he[N], ne[N], to[N], id[N], f[20][N];
long long sum, w;
void Link(int x, int y) { v[x] > v[y] ? f[0][x] = y : f[0][y] = x; }
void Chkmin(long long& x, long long y) {
  if (y < x) x = y;
}
bool Cmp(int x, int y) { return v[x] < v[y]; }
void Work() {
  n = read();
  for (int i = 1; i <= n; ++i) v[i] = read(), id[i] = i;
  for (int i = 1; i < n; ++i) Link(read(), read());
  sort(id + 1, id + n + 1, Cmp);
  for (int i = 0; i <= 19; ++i) f[i][id[1]] = id[1];
  for (int i = 2; i <= n; ++i) {
    int p = id[i];
    w = v[f[0][p]];
    for (int j = 1; j <= 19; ++j) {
      f[j][p] = f[j - 1][f[j - 1][p]];
      Chkmin(w, 1ll * (j + 1) * v[f[j][p]]);
    }
    w += v[p];
    sum += w;
  }
  printf("%I64d", sum);
}
int main() {
  Work();
  return 0;
}
inline int read() {
  char c;
  bool type = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') type = 0;
  int ans = c ^ 48;
  while ((c = getchar()) >= '0' && c <= '9')
    ans = (ans << 3) + (ans << 1) + (c ^ 48);
  return type ? ans : -ans;
}
