#include <bits/stdc++.h>
std::vector<int> G[1 + 500000];
long long a[1 + 500000];
int fth[1 + 500000][1 + 19];
void dfs(int node, int papa) {
  fth[node][0] = papa;
  for (int i = 1; i <= 19; i++) fth[node][i] = fth[fth[node][i - 1]][i - 1];
  for (auto y : G[node])
    if (y != papa) dfs(y, node);
}
std::vector<std::pair<int, int>> V;
int main() {
  FILE *fi, *fo;
  fi = stdin;
  fo = stdout;
  int n;
  fscanf(fi, "%d", &n);
  int root = 1;
  for (int i = 1; i <= n; i++) {
    fscanf(fi, "%lld", &a[i]);
    if (a[i] < a[root]) root = i;
    V.push_back({a[i], i});
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    fscanf(fi, "%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(root, root);
  std::sort(V.begin(), V.end());
  long long w = 0;
  while (!V.empty()) {
    int node = V.back().second;
    V.pop_back();
    int best = 0;
    for (int i = 0; i <= 19; i++)
      if (1LL * i * a[fth[node][i]] + a[node] + a[fth[node][i]] <
          1LL * best * a[fth[node][best]] + a[node] + a[fth[node][best]])
        best = i;
    w += 1LL * best * a[fth[node][best]] + a[node] + a[fth[node][best]];
  }
  fprintf(fo, "%lld", w - 2 * a[root]);
  return 0;
}
