func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 123466;   bool is[N];   vector<int> adj[N];   int dp[N];   int mx_dep[N];   const int inf = 1 << 22;   pair<int, int> calc_dp(int v, int p) {     int res = 0;     int mx = -inf;     if (is[v]) mx = 0;     for (auto u : adj[v])       if (u != p) {         auto cur = calc_dp(u, v);         if (cur.first == -inf) continue;         res += cur.first + 1;         res += cur.second + 1;         mx = max(mx, cur.first + 1);       }     if (mx != -inf) res -= mx;     dp[v] = res, mx_dep[v] = mx;     return {mx, res};   }   int ans = inf;   int ans_pos = 1;   int final_ans[N];   void calc(int v, int p, int load_dep, int load_res) {     int added_dep = min(load_dep, mx_dep[v]);     int cur_ans = load_res + dp[v] + added_dep;     if (cur_ans < ans) ans = cur_ans, ans_pos = v;     if (cur_ans == ans && v < ans_pos) ans_pos = v;     final_ans[v] = cur_ans;     multiset<int> s;     s.insert(load_dep);     int nload = load_dep + load_res;     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         s.insert(mx_dep[u] + 1);         nload += mx_dep[u] + 1 + dp[u] + 1;       }     for (auto u : adj[v])       if (u != p) {         if (mx_dep[u] == -inf) continue;         int cur_nload = nload - mx_dep[u] - 1 - dp[u] - 1;         s.erase(s.find(mx_dep[u] + 1));         int mx = *s.rbegin();         cur_nload -= mx;         calc(u, v, mx + 1, cur_nload + 1);         s.insert(mx_dep[u] + 1);       }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       adj[x].push_back(y);       adj[y].push_back(x);     }     int root = 1;     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       is[x] = true;       root = x;     }     calc_dp(root, 0);     calc(root, 0, 0, 0);     printf( %d n%d n , ans_pos, ans);   }   