func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     int y, ne;   } e[200010];   int f[100005], h[100005], np, vis[100005], s;   long long dp[100005], r[100005];   long long saya(int n) {     if (dp[n] != -1) return dp[n];     vis[n] = 1;     long long ans = 0, res = 0;     vector<long long> v;     for (int i = h[n]; i; i = e[i].ne) {       if (!vis[e[i].y]) {         v.push_back(saya(e[i].y));         res += r[e[i].y];       }     }     sort(v.begin(), v.end());     int j = f[n] - 1;     if (n == s) j++;     for (int i = v.size() - 1; i >= 0 && j > 0; i--, j--) {       ans += v[i];     }     if (j != 0) {       ans += 2 * min(res, 1ll * j);       r[n] = j - min(res, 1ll * j);     }     ans += f[n] - j;     return dp[n] = ans;   }   void add(int a, int b) {     e[np].y = b;     e[np].ne = h[a];     h[a] = np;     np++;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &f[i]);     np = 1;     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       add(a, b);       add(b, a);     }     scanf( %d , &s);     memset(dp, -1, sizeof(dp));     printf( %I64d n , saya(s));   }   