#include <bits/stdc++.h>
using namespace std;
int N;
int W[505050];
vector<int> E[505050];
int D[505050];
signed long long ret;
void dfs(int cur, int d) {
  D[d] = W[cur];
  signed long long mi = 1LL << 40;
  for (int i = 0; i <= 20; i++) {
    int td = max(0, d - (1 << i));
    mi = min(mi, D[td] * (i + 1LL));
  }
  if (d) ret += mi + W[cur];
  for (auto& e : E[cur])
    if (W[e] > W[cur]) dfs(e, d + 1);
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N;
  for (i = 0; i < (N); i++) cin >> W[i];
  for (i = 0; i < (N - 1); i++) {
    cin >> x >> y;
    E[x - 1].push_back(y - 1);
    E[y - 1].push_back(x - 1);
  }
  dfs(min_element(W, W + N) - W, 0);
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
