func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, k;   int value, ans;   int bads[200010], maxDelay[200010], extraDelay[200010], a[200010], v[200010];   vector<int> T[200010], val[200010], pre[200010], post[200010];   void dfs(int x, int f) {     bads[x] = 0;     maxDelay[x] = 0;     extraDelay[x] = 0;     for (int i = 0; i < T[x].size(); ++i) {       int y = T[x][i];       if (y != f) {         dfs(y, x);         bads[x] += bads[y];         if (bads[y] == 0) {           maxDelay[x] += maxDelay[y];         } else {           extraDelay[x] = max(extraDelay[x], maxDelay[y]);         }       }     }     if (a[x] < value) {       bads[x]++;       maxDelay[x] = 0;     } else {       maxDelay[x] += extraDelay[x] + 1;     }   }   void dfs(int x, int f, int fBads, int fMaxDelay) {     if (a[x] >= value) {       int finalVal = maxDelay[x] - extraDelay[x];       finalVal += (fBads == 0 ? fMaxDelay + extraDelay[x]                               : max(fMaxDelay, extraDelay[x]));       ans = max(ans, finalVal);     }     for (int i = 0; i < T[x].size(); ++i) {       int y = T[x][i];       if (y == f) {         val[x][i] = (fBads > 0 ? fMaxDelay : 0);       } else {         val[x][i] = (bads[y] > 0 ? maxDelay[y] : 0);       }     }     int sz = T[x].size();     pre[x][0] = val[x][0];     post[x][sz - 1] = val[x][sz - 1];     for (int i = 1; i < sz; ++i) pre[x][i] = max(val[x][i], pre[x][i - 1]);     for (int i = sz - 2; i >= 0; --i) post[x][i] = max(val[x][i], post[x][i + 1]);     for (int i = 0; i < T[x].size(); ++i) {       int y = T[x][i];       if (y == f) continue;       if (a[x] < value) {         dfs(y, x, bads[x] - bads[y] + fBads, 0);       } else {         int newBads = bads[x] - bads[y] + fBads;         int newMaxDelay =             maxDelay[x] - extraDelay[x] - (bads[y] == 0 ? maxDelay[y] : 0) +             (fBads == 0 ? fMaxDelay : 0) +             max((i == 0 ? 0 : pre[x][i - 1]), (i == sz - 1 ? 0 : post[x][i + 1]));         dfs(y, x, newBads, newMaxDelay);       }     }   }   void reset() {}   int check(int tval) {     reset();     value = tval;     ans = 0;     dfs(1, 0);     dfs(1, 0, 0, 0);     return (ans >= k);   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       v[i] = a[i];     }     sort(v + 1, v + n + 1);     for (int i = 1; i < n; ++i) {       int a, b;       cin >> a >> b;       T[a].push_back(b);       T[b].push_back(a);     }     for (int i = 1; i <= n; ++i) {       val[i].resize(T[i].size(), 0);       pre[i].resize(T[i].size(), 0);       post[i].resize(T[i].size(), 0);     }     int lo = 0, hi = n + 1;     while (hi - lo > 1) {       int mid = (lo + hi) / 2;       if (check(v[mid]))         lo = mid;       else         hi = mid;     }     cout << v[lo];   }   