#include <bits/stdc++.h>
using namespace std;
const long long highestApples = 1000000000;
int n;
long long allApples;
long long apples[100000];
long long sons[100000];
long long minAdd[100000];
long long maxApples[100000];
vector<int> edges[100000];
bool seen[100000];
long long gcd(long long a, long long b) {
  long long c = max(a, b);
  long long d = min(a, b);
  while (d != 0) c = c % d, swap(c, d);
  return c;
}
long long lcm(long long a, long long b) {
  if (a >= highestApples || b >= highestApples)
    return highestApples;
  else
    return (a * b) / gcd(a, b);
}
void dfs1(int me) {
  long long sonsVal = 0;
  long long lcmVal = 1;
  seen[me] = true;
  for (int son : edges[me])
    if (!seen[son]) dfs1(son), sonsVal++, lcmVal = lcm(lcmVal, minAdd[son]);
  sons[me] = sonsVal;
  minAdd[me] = (sonsVal == 0) ? 1 : sons[me] * lcmVal;
}
void dfs2(int me) {
  long long minMul = std::numeric_limits<long long>::max();
  seen[me] = true;
  for (int son : edges[me])
    if (!seen[son])
      dfs2(son), minMul = min(minMul, maxApples[son] / (minAdd[me] / sons[me]));
  if (sons[me] == 0)
    maxApples[me] = apples[me];
  else
    maxApples[me] = minMul * minAdd[me];
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> apples[i], allApples += apples[i];
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }
  dfs1(0);
  for (int i = 0; i < n; ++i) seen[i] = false;
  dfs2(0);
  for (int i = 0; i < n; ++i) seen[i] = false;
  cout << allApples - maxApples[0] << endl;
  return 0;
}
