#include <bits/stdc++.h>
using namespace std;
bool overflow = false;
int N;
int a[100010];
vector<int> graph[100010];
long long cap[100010], mul[100010];
long long prod(long long x, long long y) {
  if (x == 0 || y == 0) return 0;
  if (x > (1ll << 60) / y) {
    overflow = true;
    return (1ll << 60);
  }
  return x * y;
}
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
long long lcm(long long x, long long y) {
  if (x == 0 || y == 0) return x + y;
  long long g = gcd(x, y);
  return prod(x / g, y);
}
void dfs(int p, int x) {
  int i, deg = 0;
  for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {
    int y = graph[x][i];
    if (y != p) {
      deg++;
      dfs(x, y);
    }
  }
  if (deg == 0) {
    cap[x] = a[x];
    mul[x] = 1;
    return;
  }
  long long tmp = 0;
  for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {
    int y = graph[x][i];
    if (y != p) tmp = lcm(tmp, mul[y]);
  }
  long long tmp2 = (1ll << 60);
  for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {
    int y = graph[x][i];
    if (y != p) tmp2 = min(tmp2, cap[y] / tmp * tmp);
  }
  cap[x] = prod(tmp2, deg);
  mul[x] = prod(tmp, deg);
}
int main(void) {
  int i;
  cin >> N;
  for ((i) = 0; (i) < (int)(N); (i)++) scanf("%d", &a[i]);
  for ((i) = 0; (i) < (int)(N - 1); (i)++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  dfs(-1, 0);
  long long ans = 0;
  for ((i) = 0; (i) < (int)(N); (i)++) ans += a[i];
  if (!overflow) ans -= cap[0];
  cout << ans << endl;
  return 0;
}
