func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, q, u, v;   pair<int, vector<int> > P[100011][25];   vector<int> residents[100011];   vector<int> adj[100001];   int parent[100001];   int L[100001];   int checker;   vector<int> mergevec(vector<int>& A, vector<int>& B, int sz) {     vector<int> sol;     int ap = 0, bp = 0;     while (sz != 0 && ap != A.size() && bp != B.size()) {       if (A[ap] < B[bp]) {         if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--;         ap++;       } else {         if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--;         bp++;       }     }     while (sz != 0 && ap != A.size()) {       if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--;       ap++;     }     while (sz != 0 && bp != B.size()) {       if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--;       bp++;     }     return sol;   }   void process() {     int i, j;     for (i = 1; i <= n; i++) {       for (j = 0; j <= 20; j++) {         P[i][j].first = -1;       }     }     for (i = 1; i <= n; i++) {       P[i][0].first = parent[i];       P[i][0].second = residents[i];     }     for (j = 1; 1 << j < n; j++) {       for (i = 1; i <= n; i++) {         if (P[i][j - 1].first != -1) {           P[i][j].first = P[P[i][j - 1].first][j - 1].first;           P[i][j].second = mergevec(P[i][j - 1].second,                                     P[P[i][j - 1].first][j - 1].second, 10);         }       }     }   }   int lca(int p, int q) {     int tmp, log, i;     if (L[p] < L[q]) tmp = p, p = q, q = tmp;     for (log = 1; 1 << log <= L[p]; log++)       ;     log--;     for (i = log; i >= 0; i--) {       if (L[p] - (1 << i) >= L[q]) {         p = P[p][i].first;       }     }     if (p == q) return p;     for (i = log; i >= 0; i--)       if (P[p][i].first != -1 && P[p][i].first != P[q][i].first)         p = P[p][i].first, q = P[q][i].first;     return parent[p];   }   vector<int> path(int u, int levelpar, int sz) {     vector<int> sol = residents[u];     for (int i = checker; i >= 0; i--) {       if (P[u][i].first != -1) {         if (L[P[u][i].first] >= levelpar) {           sol = mergevec(sol, P[u][i].second, sz);           u = P[u][i].first;         }       }     }     return sol;   }   void dfs(int start, int p) {     parent[start] = p;     if (p == -1)       L[start] = 1;     else       L[start] = L[p] + 1;     for (int i = 0; i < adj[start].size(); i++) {       if (adj[start][i] != p) {         dfs(adj[start][i], start);       }     }   }   int main() {     int a;     scanf( %d%d%d , &n, &m, &q);     checker = min((int)(log2(n) + 3), (int)20);     for (int i = 0; i < n - 1; i++) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < m; i++) {       scanf( %d , &u);       if (residents[u].size() < 10) residents[u].push_back(i + 1);     }     for (int i = 1; i <= 100000; i++)       sort(residents[i].begin(), residents[i].end());     dfs(1, -1);     process();     for (int i = 0; i < q; i++) {       scanf( %d%d%d , &u, &v, &a);       int lcaa = lca(u, v);       vector<int> v1 = path(u, L[lcaa], a), v2 = path(v, L[lcaa], a);       vector<int> sol = mergevec(v1, v2, a);       sol = mergevec(sol, residents[lcaa], a);       printf( %d  , (int)sol.size());       for (int j = 0; j < sol.size(); j++) {         printf( %d  , sol[j]);       }       printf(  n );     }     return 0;   }   