func_code_string: #include <bits/stdc++.h>   const int INF = 1e9 + 100;   const long long lINF = 4e18;   const double EPS = 1e-12;   using namespace std;   const int N = 5e5 + 100;   int n, k, h[N], s[N], mn = INF, mxh[N], should = INF;   vector<int> graph[N];   vector<int> can, need;   void dfs1(int v, int par = -1, int mx = INF) {     mxh[v] = mx;     mx = min(mx, h[v]);     can.push_back(mx);     for (auto j : graph[v]) {       if (j != par) dfs1(j, v, mx);     }   }   void dfs2(int v, int par, map<int, int>& ans) {     map<int, int> ans2;     for (auto j : graph[v]) {       if (j != par) {         dfs2(j, v, ans2);         if (ans.size() < ans2.size()) {           swap(ans, ans2);         }         for (auto k : ans2) {           ans[k.first] += k.second;         }         ans2.clear();       }     }     if (mxh[v] >= need[0] && h[v] <= should) {       bool flag = true;       ans[need[0]]++;       map<int, int>::reverse_iterator j = ans.rbegin();       for (int i = 0; i < (int)need.size(); i++) {         while (j != ans.rend() && j->second == 0) {           j++;         }         if (j == ans.rend() || j->first < need[i]) {           flag = false;         } else {           j->second--;         }       }       if (flag) {         mn = min(mn, need[0] - h[v]);       }       ans.clear();     } else {       while (ans.size() > 0 && ans.rbegin()->first > h[v]) {         int p = ans.rbegin()->second;         ans.erase(ans.rbegin()->first);         ans[h[v]] += p;       }       ans[h[v]]++;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);     }     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d , &s[i]);     }     dfs1(1);     sort(s, s + k);     reverse(s, s + k);     sort((can).begin(), (can).end());     reverse((can).begin(), (can).end());     for (int i = 0, j = 0, delta = 0; i < k; i++) {       delta--;       while (j < (int)can.size() && can[j] >= s[i]) {         j++;         delta++;       }       if (j < i + 1) {         should = min(should, s[i] - 1);       }       if (delta < 0) {         need.push_back(s[i]);         delta++;       }     }     if (need.size() == 0) {       cout << 0 << endl;     } else {       map<int, int> res;       dfs2(1, -1, res);       if (mn == INF) {         cout <<  -1  << endl;       } else {         cout << mn << endl;       }     }     return 0;   }   