func_code_string: #include <bits/stdc++.h>   using namespace std;   struct NODE {     int to, next;   } node[200000 + 10];   long long dp[100000 + 10], k[100000 + 10];   int n, tol;   int head[100000 + 10];   void addedge(int from, int to) {     node[tol].to = to;     node[tol].next = head[from];     head[from] = tol++;   }   void tree_dp(int now, int fa) {     priority_queue<long long, vector<long long>, less<long long> > que;     while (!que.empty()) que.pop();     for (int i = head[now]; i != -1; i = node[i].next) {       int v = node[i].to;       if (v != fa) {         k[v]--;         tree_dp(v, now);         que.push(dp[v]);       }     }     while (k[now] && !que.empty()) {       k[now]--;       int p = que.top();       dp[now] += que.top() + 2;       que.pop();     }     for (int i = head[now]; i != -1; i = node[i].next) {       if (k[now] == 0) break;       int v = node[i].to;       if (v != fa) {         long long t = min(k[now], k[v]);         dp[now] += t * 2;         k[now] -= t;       }     }   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(head, -1, sizeof(head));       tol = 0;       for (int i = 1; i <= n; i++) scanf( %I64d , &k[i]);       for (int i = 1; i <= n - 1; i++) {         int u, v;         scanf( %d %d , &u, &v);         addedge(u, v);         addedge(v, u);       }       int root;       scanf( %d , &root);       memset(dp, 0, sizeof(dp));       tree_dp(root, 0);       printf( %I64d n , dp[root]);     }     return 0;   }   