func_code_string: #include <bits/stdc++.h>   using namespace std;   int L[100010];   int P[100010][20];   vector<int> pp[100010][20];   int T[100010];   vector<int> tt[100010];   int arr[100010];   vector<int> graph[100010];   vector<int> fnc(vector<int> &a, vector<int> &b) {     vector<int> ans;     int aa = a.size(), bb = b.size(), i, j, shajib = 0;     for (i = 0, j = 0; i + j < aa + bb && shajib < 10;) {       if (i == aa) {         ans.push_back(b[j]);         j++;         shajib++;       } else if (j == bb) {         ans.push_back(a[i]);         i++;         shajib++;       } else {         if (a[i] == b[j]) {           i++;         } else if (a[i] > b[j]) {           ans.push_back(b[j]);           j++;           shajib++;         } else {           ans.push_back(a[i]);           i++;           shajib++;         }       }     }     return ans;   }   void dfs(int src, int par) {     if (src == -1)       L[par] = 1;     else       L[par] = L[src] + 1;     T[par] = src;     int len = graph[par].size();     for (int i = 0; i < (int)graph[par].size(); i++) {       int v = graph[par][i];       if (v != src) {         dfs(par, v);       }     }   }   vector<int> query(int n, int p, int q) {     int log = 1, i, j, temp;     if (L[p] < L[q]) {       temp = q;       q = p;       p = temp;     }     log = log2(n);     vector<int> os;     os = fnc(os, tt[p]);     for (j = log; j >= 0; j--) {       if (L[p] - (1 << j) >= L[q]) {         os = fnc(os, pp[p][j]);         p = P[p][j];       }     }     if (p == q) return os;     os = fnc(os, tt[q]);     for (j = log; j >= 0; j--) {       if (P[p][j] != -1 && P[p][j] != P[q][j]) {         os = fnc(os, pp[p][j]);         os = fnc(os, pp[q][j]);         p = P[p][j], q = P[q][j];       }     }     os = fnc(os, pp[p][0]);     return os;   }   void lca(int n) {     memset(P, -1, sizeof(P));     int i, j;     for (i = 1; i <= n; i++) {       P[i][0] = T[i];       if (T[i] != -1) pp[i][0] = fnc(pp[i][0], tt[T[i]]);     }     for (j = 1; (1 << j) < n; j++) {       for (i = 1; i <= n; i++) {         if (P[i][j - 1] != -1) {           P[i][j] = P[P[i][j - 1]][j - 1];           pp[i][j] = fnc(pp[i][j], pp[P[i][j - 1]][j - 1]);           pp[i][j] = fnc(pp[i][j], pp[i][j - 1]);         }       }     }   }   int main() {     int i, j, n, m, t, a, b, k, c;     scanf( %d%d%d , &n, &m, &k);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &a, &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     for (i = 1; i <= m; i++) {       scanf( %d , &a);       tt[a].push_back(i);     }     for (i = 1; i <= n; i++) {       sort(tt[i].begin(), tt[i].end());       a = tt[i].size();       while (a > 10) {         tt[i].pop_back();         a--;       }     }     dfs(-1, 1);     lca(n);     vector<int> os;     for (i = 1; i <= k; i++) {       scanf( %d%d%d , &a, &b, &c);       os = query(n, a, b);       c = min(c, (int)os.size());       a = 0;       printf( %d  , c);       for (auto it = os.begin(); a < c && it != os.end(); a++, it++) {         printf( %d  , (*it));       }       printf(  n );     }   }   