func_code_string: #include <bits/stdc++.h>   using namespace std;   long long int dp[100000 + 10];   vector<int> ma[100000 + 10];   int a[100000 + 10];   long long int dp1[100000 + 10];   long long int gcd(long long int x, long long int y) {     return y == 0 ? x : gcd(y, x % y);   }   long long int lcm(long long int x, long long int y) {     long long int tmp = gcd(x, y);     return x / tmp * y;   }   void tree_dp(int fa, int n) {     if (ma[n].size() == 1) {       dp1[n] = 1;       dp[n] = (long long int)a[n];       return;     }     int i;     long long int tmp = 1;     long long int mins = LLONG_MAX;     for (i = 0; i < ma[n].size(); i++) {       if (ma[n][i] == fa) continue;       tree_dp(n, ma[n][i]);       tmp = lcm(tmp, dp1[ma[n][i]]);       if (tmp == 0) tmp = 1;       mins = min(mins, dp[ma[n][i]]);     }     dp[n] = (long long int)a[n] + mins / tmp * tmp * (ma[n].size() - 1);     dp1[n] = tmp * (ma[n].size() - 1);   }   int main() {     int n;     cin >> n;     int i;     long long int all = 0;     for (i = 1; i <= n; i++) {       cin >> a[i];       ma[i].clear();       all += a[i];     }     ma[1].push_back(1);     for (i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       ma[x].push_back(y);       ma[y].push_back(x);     }     tree_dp(1, 1);     cout << all - dp[1] << endl;     return 0;   }   