func_code_string: #include <bits/stdc++.h>   using namespace std;   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   const int N = (int)2e5 + 5;   const int maxN = (int)1e6 + 6;   const long long Mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long Inf = (long long)1e18;   struct lowest_common_ancestor {     const static int N = 1e5 + 5;     const static int k = 17;     int par[N][k + 1], lev[N];     vector<vector<int>> g, city;     vector<int> ID[N][k + 1];     lowest_common_ancestor() {       for (int i = 0; i < N; ++i) {         for (int j = 0; j <= k; ++j) par[i][j] = 0;         lev[i] = 0;       }     }     vector<int> merge(vector<int> &a, vector<int> &b) {       vector<int> tmp;       auto i = a.begin(), j = b.begin();       for (int k = 1; k <= min(10, (int)a.size() + (int)b.size()); ++k) {         if (i != a.end() and j != b.end()) {           if (*i < *j)             tmp.push_back(*i), ++i;           else             tmp.push_back(*j), ++j;         } else if (i != a.end())           tmp.push_back(*i), ++i;         else           tmp.push_back(*j), ++j;       }       return tmp;     }     void build(int s, int p = 0) {       lev[s] = 1 + lev[p];       par[s][0] = p;       ID[s][0].assign(city[p].begin(), city[p].end());       for (int i = 1; i <= k; ++i) {         par[s][i] = par[par[s][i - 1]][i - 1];         ID[s][i] = merge(ID[s][i - 1], ID[par[s][i - 1]][i - 1]);       }       for (int i : g[s])         if (i != p) build(i, s);     }     void getLCA(int a, int b, int num) {       if (lev[a] < lev[b]) swap(a, b);       vector<int> res(city[a].begin(), city[a].end());       int d = lev[a] - lev[b];       int t = b;       for (int i = k; i >= 0; --i) {         if ((d >> i) & 1) {           res = merge(res, ID[a][i]);           a = par[a][i];         }       }       if (a == b) {         printf( %d , min((int)res.size(), num));         for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]);         cout <<   n ;         return;       }       for (int i = k; i >= 0; --i) {         if (par[a][i] != par[b][i]) {           res = merge(res, ID[a][i]);           res = merge(res, ID[b][i]);           b = par[b][i];           a = par[a][i];         }       }       res = merge(res, city[par[a][0]]);       res = merge(res, city[t]);       printf( %d , min((int)res.size(), num));       for (int i = 0; i < min(num, (int)res.size()); ++i) printf(  %d , res[i]);       cout <<   n ;       return;     }     void solve() {       int n = Int(), m = Int(), q = Int();       g.resize(n + 1);       city.resize(n + 1);       for (int i = 1; i < n; ++i) {         int x = Int(), y = Int();         g[x].emplace_back(y);         g[y].emplace_back(x);       }       for (int i = 1; i <= m; ++i) {         int c = Int();         city[c].emplace_back(i);       }       for (int i = 1; i <= n; ++i) {         sort(city[i].begin(), city[i].end());         while ((int)city[i].size() > 10) city[i].pop_back();       }       build(1);       while (q--) {         int l = Int(), r = Int(), t = Int();         getLCA(l, r, t);       }     }   };   lowest_common_ancestor lca;   int main() {     int test = 1, tc = 0;     while (test--) {       lca.solve();     }     return 0;   }   