#include <bits/stdc++.h>
using namespace std;
long long lcm, p[400005], du[400005], mi, mul = 1, sum, a[400005], gc;
int flag, n, u, v, i, ee, e[400005], nex[400005], head[400005];
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
void add(int u, int v) {
  e[++ee] = v;
  nex[ee] = head[u];
  head[u] = ee;
}
void dfs(int u) {
  if (flag == 1) return;
  if (du[u] == 1) {
    if (lcm == 0)
      lcm = p[u];
    else
      lcm = (lcm * p[u]) / gcd(lcm, p[u]);
    mi = (mi < a[u] * p[u] ? mi : a[u] * p[u]);
  }
  int j = head[u];
  while (j != 0) {
    if (p[e[j]] == 0) {
      p[e[j]] = p[u] * (du[u] - 1);
      if (p[e[j]] > sum) {
        flag = 1;
        return;
      }
      dfs(e[j]);
    }
    j = nex[j];
  }
}
int main() {
  scanf("%d", &n);
  mi = 1000000000000000;
  sum = 0;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum += a[i];
  }
  for (i = 1; i <= n - 1; i++) {
    scanf("%d%d", &u, &v);
    du[u]++;
    du[v]++;
    add(u, v);
    add(v, u);
  }
  du[1]++;
  p[1] = 1;
  dfs(1);
  if (mi < lcm || flag == 1) {
    printf("%I64d\n", sum);
    return 0;
  }
  printf("%I64d\n", sum - (mi - mi % lcm));
  return 0;
}
