#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
long long gcd(long long a, long long b) {
  long long tmp;
  if (a > b) {
    tmp = a, a = b, b = tmp;
  }
  while (b) {
    tmp = a % b, a = b, b = tmp;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct Node {
  long long val, mul;
  int child;
  vector<int> adj;
  Node() {
    child = 0;
    val = 0;
    mul = 1;
    adj.clear();
  }
} node[MAXN];
int visited[MAXN];
void dfs1(int cur) {
  int len = node[cur].adj.size();
  for (int i = 0; i < len; i++) {
    int nd = node[cur].adj[i];
    if (!visited[nd]) {
      node[cur].child++;
      visited[nd] = 1;
      dfs1(nd);
      visited[nd] = 0;
      node[cur].mul = lcm(node[cur].mul, node[nd].mul);
    }
  }
  node[cur].mul *= (node[cur].child == 0) ? 1 : node[cur].child;
}
void dfs2(int cur) {
  int len = node[cur].adj.size();
  for (int i = 0; i < len; i++) {
    int nd = node[cur].adj[i];
    if (!visited[nd]) {
      visited[nd] = 1;
      node[nd].mul = node[cur].mul / node[cur].child;
      dfs2(nd);
      visited[nd] = 0;
    }
  }
}
int main(void) {
  int n;
  long long ans = 0, minnum = 1e18;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> node[i].val;
    ans += node[i].val;
  }
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    node[x].adj.push_back(y);
    node[y].adj.push_back(x);
  }
  memset(visited, 0, sizeof(visited));
  visited[1] = 1;
  dfs1(1);
  dfs2(1);
  visited[1] = 0;
  for (int i = 1; i <= n; i++) {
    if (node[i].child == 0 && node[i].mul != 0) {
      minnum = min(minnum, node[i].val / node[i].mul);
    }
  }
  minnum *= node[1].mul;
  ans -= minnum;
  cout << ans << endl;
  return 0;
}
