#include <bits/stdc++.h>
using namespace std;
const int N = 1100000;
int mod = 998244353;
int a[1000010];
int fa[500010][20];
int n, idx;
vector<int> g[1000010];
long long ans;
void dfs(int t, int f) {
  if (t != f) {
    fa[t][0] = f;
  }
  for (int i = 1; i < 20; ++i) {
    if (!fa[t][i - 1]) break;
    fa[t][i] = fa[fa[t][i - 1]][i - 1];
  }
  for (int u : g[t]) {
    if (u == f) continue;
    dfs(u, t);
  }
  long long res = -1;
  int i = 0;
  for (i = 0; i < 20; ++i) {
    if (!fa[t][i]) break;
    long long tot = (long long)(i + 1) * a[fa[t][i]];
    if (res == -1 || res > tot) res = tot;
  }
  if (t != f) {
    long long tot = (long long)(i + 1) * a[idx];
    if (res == -1 || res > tot) res = tot;
  }
  if (res != -1) {
    res += a[t];
    ans += res;
  }
}
int main() {
  cin >> n;
  idx = 1;
  memset(fa, 0, sizeof(fa));
  for (int i = 1; i < n + 1; ++i) {
    scanf("%d", &a[i]);
    if (a[i] < a[idx]) {
      idx = i;
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  ans = 0;
  dfs(idx, idx);
  cout << ans << endl;
}
