func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 5;   const long long inf = 1e18;   int f[maxn][32], rt;   long long ans, a[maxn];   vector<int> G[maxn];   void dfs(int u, int p) {     long long d = 0;     f[u][0] = p;     for (d = 1; d <= 20; d++) {       if (f[u][d - 1] != -1) f[u][d] = f[f[u][d - 1]][d - 1];     }     long long tmp = inf;     for (d = 0; d <= 20; d++) {       if (f[u][d] != -1)         tmp = min(tmp, (d + 1) * a[f[u][d]] + a[u]);       else         break;     }     tmp = min(tmp, (d + 1) * a[rt] + a[u]);     if (p != -1) ans += tmp;     for (int v : G[u])       if (v != p) dfs(v, u);   }   int main() {     ios::sync_with_stdio(false);     memset(f, -1, sizeof(f));     int n;     cin >> n;     a[rt] = inf;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] < a[rt]) rt = i;     }     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(rt, -1);     cout << ans << endl;   }   