#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 99, Lg = 20, inf = 1e9;
int n, mn = inf, rt, a[N], Par[Lg][N];
vector<int> g[N];
long long ans;
void dfs(int x, int par) {
  long long res = 1ll * inf * inf;
  Par[0][x] = par;
  for (int lg = 1; lg < Lg; lg++) Par[lg][x] = Par[lg - 1][Par[lg - 1][x]];
  for (int lg = 0; lg < Lg; lg++)
    res = min(res, 1ll * a[Par[lg][x]] * (lg + 1));
  ;
  if (x != rt) ans += res + a[x];
  for (int i = 0; i < g[x].size(); i++)
    if (g[x][i] != par) dfs(g[x][i], x);
}
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &a[i]);
    ;
    if (a[i] < mn) mn = a[i], rt = i;
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    ;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(rt, rt);
  cout << ans;
}
