#include <bits/stdc++.h>
using namespace std;
long long int a[100001];
int vis[100001];
int leaf[100001];
long long int wt[100001];
int n;
vector<int> adj[100001];
long long int sum = 0;
long long int __gcd(long long int a, long long int b) {
  if (b > a) return __gcd(b, a);
  if (b == 0) return a;
  return __gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  long long int val = __gcd(a, b);
  val = a / val;
  val = val * b;
  if (val > 20000000000000) {
    cout << sum << endl;
    exit(0);
  }
  return val;
}
void dfs(int idx, long long int val) {
  if (val > 20000000000000) {
    printf("%lld\n", sum);
    exit(0);
  }
  vis[idx] = 1;
  long long int cnt = 0;
  for (int i = 0; i < adj[idx].size(); i++) {
    if (!vis[adj[idx][i]]) {
      cnt++;
    }
  }
  if (cnt == 0) {
    leaf[idx] = 1;
    wt[idx] = val;
  }
  cnt = cnt * val;
  for (int i = 0; i < adj[idx].size(); i++) {
    if (!vis[adj[idx][i]]) dfs(adj[idx][i], cnt);
  }
  return;
}
long long int valid(long long int val) {
  for (int i = 0; i < n; i++) {
    if (leaf[i]) {
      if ((val / wt[i]) > a[i]) return 0;
    }
  }
  return 1;
}
long long int bfind1(long long int i, long long int j, long long int val) {
  if (i + 1 == j) {
    if (valid(j * val))
      return j;
    else
      return i;
  }
  if (valid(j * val)) return j;
  long long int mid = (i + j) / 2;
  if (valid(mid * val))
    return bfind1(mid, j, val);
  else
    return bfind1(i, mid - 1, val);
}
int main() {
  scanf("%d", &n);
  memset(wt, 0, sizeof wt);
  memset(leaf, 0, sizeof leaf);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum = sum + a[i];
  }
  int x, y;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d", &x);
    scanf("%d", &y);
    x--;
    y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  memset(vis, 0, sizeof vis);
  dfs(0, 1);
  long long int val = 1;
  for (int i = 0; i < n; i++) {
    if (leaf[i]) {
      val = lcm(val, wt[i]);
    }
  }
  long long int limi = 20000000000000 / val;
  long long int idx = bfind1(0, limi, val);
  long long int apples = idx * val;
  cout << sum - apples << endl;
}
