#include <bits/stdc++.h>
using namespace std;
int a[501010] = {0}, f[505050][30] = {0}, st[505050], ff[505050][30];
int n, m, z = 0;
long long ans = 0;
struct Edge {
  int to, next;
} bus[505050];
inline void AddE(int aa, int bb) {
  if (a[aa] > a[bb]) swap(aa, bb);
  f[bb][0] = aa;
  bus[++z].to = bb;
  bus[z].next = st[aa];
  st[aa] = z;
}
inline void dfs(int now) {
  long long tmp = 99999999999;
  for (int j = 0; j <= 20; j++)
    tmp = min(tmp, (long long)(j)*a[f[now][j]] + a[now] + a[f[now][j]]);
  ans += tmp;
  for (int i = st[now]; i; i = bus[i].next) dfs(bus[i].to);
}
inline void dfs1(int now) {
  for (int j = 1; j <= 20; j++) {
    f[now][j] = f[f[now][j - 1]][j - 1];
    ff[now][j] = now;
    for (int k = j - 1; k >= 0; k--) ff[now][j] = f[ff[now][j]][k];
  }
  for (int i = st[now]; i; i = bus[i].next) dfs1(bus[i].to);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  int aa, bb, root = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[root] > a[i]) root = i;
  }
  f[root][0] = root;
  for (int i = 1; i < n; i++) {
    cin >> aa >> bb;
    AddE(aa, bb);
  }
  dfs1(root);
  for (int i = st[root]; i; i = bus[i].next) dfs(bus[i].to);
  cout << ans << endl;
  return 0;
}
