#include <bits/stdc++.h>
using namespace std;
vector<int> edge[500010];
int val[500010], father[500010][20], root;
long long ans;
void dfs(int u) {
  ans += 1ll * val[u] * edge[u].size();
  for (auto v : edge[u]) {
    if (father[u][0] == v) {
      continue;
    }
    father[v][0] = u;
    for (int i = 1; i < 20; ++i) {
      father[v][i] = father[father[v][i - 1]][i - 1];
    }
    dfs(v);
  }
}
void dfs2(int u) {
  for (auto v : edge[u]) {
    if (father[u][0] == v) {
      continue;
    }
    dfs2(v);
  }
  if (u != root && father[u][0] != root) {
    long long max_delta = 0;
    for (int i = 1;; ++i) {
      int v = father[u][i];
      if (v == 0) {
        v = root;
      }
      if (val[father[u][0]] - 1ll * val[v] * i - val[v] > max_delta) {
        max_delta = val[father[u][0]] - 1ll * val[v] * i - val[v];
      }
      if (v == root) {
        break;
      }
    }
    ans -= max_delta;
  }
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", val + i);
    if (root == 0 || val[i] < val[root]) {
      root = i;
    }
  }
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  dfs(root);
  dfs2(root);
  cout << ans << endl;
  return 0;
}
