#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 500005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
  string s = "/home/jslijin/jslijin/code/";
  freopen((s + "code.in").c_str(), "r", stdin);
  freopen((s + "code.out").c_str(), "w", stdout);
}
int n, d[N], rt = 0, mm = oo, x, y, a[N];
vector<int> V[N];
long long ans = 0;
void dfs(int x, int p, int dep) {
  d[dep] = x;
  long long ret = a[x] + a[p], i = 1;
  for (; (1 << i) < dep; ++i)
    ret = ((ret) < (a[x] + (long long)a[d[dep - (1 << i)]] * (i + 1))
               ? (ret)
               : (a[x] + (long long)a[d[dep - (1 << i)]] * (i + 1)));
  ret = ((ret) < (a[x] + (long long)a[rt] * (i + 1))
             ? (ret)
             : (a[x] + (long long)a[rt] * (i + 1))),
  ans += (x != rt) * ret;
  for (auto y : V[x])
    if (y != p) dfs(y, x, dep + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i)
    scanf("%d", &a[i]), a[i] < mm ? mm = a[i], rt = i : 0;
  for (int i = (1); i <= (n - 1); ++i)
    scanf("%d%d", &x, &y), V[x].push_back(y), V[y].push_back(x);
  dfs(rt, 0, 0), printf("%lld\n", ans);
  return 0;
}
