#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int n, a[N], rt = 1, ba[30], sta[N], top = 0;
vector<int> e[N];
long long ans;
void dfs(int u, int ff) {
  sta[++top] = u;
  if (ff) {
    long long w = a[sta[top - 1]];
    int i = 1;
    for (; top - ba[i] > 0; i++)
      if (w > (long long)(i + 1) * a[sta[top - ba[i]]])
        w = (long long)(i + 1) * a[sta[top - ba[i]]];
    if (w > (long long)(i + 1) * a[rt]) w = (long long)(i + 1) * a[rt];
    ans += w + (long long)a[u];
  }
  for (auto v : e[u])
    if (v ^ ff) dfs(v, u);
  --top;
}
int main() {
  ba[0] = 1;
  for (int i = 1; i < 25; i++) ba[i] = ba[i - 1] * 2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] < a[rt]) rt = i;
  }
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), e[x].push_back(y), e[y].push_back(x);
  dfs(rt, 0), printf("%I64d\n", ans);
  return 0;
}
