func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 200005, L = 20;   const int INF = 1 << 30;   struct node {     int u, v, nxt;   } edge[M];   int head[N], mcnt;   void add_edge(int u, int v) {     mcnt++;     edge[mcnt].u = u;     edge[mcnt].v = v;     edge[mcnt].nxt = head[u];     head[u] = mcnt;   }   vector<int> G[N];   int dfn[N], tot;   int deep[N];   int pa[N][L + 1];   bool Chosen[N];   int OnVtree[N], cnt;   int S[N], top;   int n, m, k;   int d[N][2];   void dfs(int u, int fa) {     dfn[u] = ++tot;     deep[u] = deep[fa] + 1;     for (int i = head[u]; i; i = edge[i].nxt) {       int v = edge[i].v;       if (v == fa) continue;       pa[v][0] = u;       dfs(v, u);     }   }   void Init() {     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       add_edge(u, v);       add_edge(v, u);     }     dfs(1, 0);     for (int j = 1; j <= L; j++)       for (int i = 1; i <= n; i++) pa[i][j] = pa[pa[i][j - 1]][j - 1];   }   int LCA(int x, int y) {     if (deep[x] < deep[y]) swap(x, y);     for (int j = L; j >= 0; j--)       if (deep[pa[x][j]] >= deep[y]) x = pa[x][j];     if (x == y) return x;     for (int j = L; j >= 0; j--)       if (pa[x][j] != pa[y][j]) x = pa[x][j], y = pa[y][j];     return pa[x][0];   }   struct mode {     int u, dfn;   } p[N];   bool cmp(mode a, mode b) { return a.dfn < b.dfn; }   void add_tree(int u, int v) {     G[u].push_back(v);     G[v].push_back(u);   }   void Get_vtree() {     sort(p + 1, p + k + 1, cmp);     top = 0;     S[++top] = p[1].u;     for (int i = 2; i <= k; i++) {       int u = p[i].u, v = S[top];       int lca = LCA(u, v);       if (v == lca)         S[++top] = u;       else {         int ntop = top;         while (ntop > 0 && deep[S[ntop]] > deep[lca]) ntop--;         for (int j = ntop + 1; j + 1 <= top; j++) {           add_tree(S[j], S[j + 1]);         }         long long pos = S[ntop + 1];         if (ntop < top) {           add_tree(pos, lca);         }         top = ntop;         if (S[top] != lca) {           OnVtree[++cnt] = lca;           S[++top] = lca;         }         S[++top] = u;       }     }     for (int j = 1; j + 1 <= top; j++) add_tree(S[j], S[j + 1]);   }   void DP(int u, int fa) {     d[u][0] = 1, d[u][1] = 0;     if (Chosen[u]) {       for (int i = 0, sz = G[u].size(); i < sz; i++) {         int v = G[u][i];         if (v == fa) continue;         DP(v, u);         d[u][1] += d[v][0];         d[u][0] += d[v][0];       }     } else {       int mx = INF;       int sum = 0;       for (int i = 0, sz = G[u].size(); i < sz; i++) {         int v = G[u][i];         if (v == fa) continue;         DP(v, u);         d[u][0] += min(d[v][0], d[v][1]);         sum += d[v][0];         d[u][1] += d[v][0];         mx = min(mx, d[v][1] - d[v][0]);       }       d[u][0] = min(d[u][0], sum);       d[u][1] += mx;     }   }   bool check() {     for (int i = 1; i <= k; i++) {       int u = OnVtree[i];       for (int i = head[u]; i; i = edge[i].nxt) {         int v = edge[i].v;         if (Chosen[v]) return true;       }     }     return false;   }   void Solve() {     scanf( %d , &k);     cnt = k;     for (int i = 1; i <= k; i++) {       int u;       scanf( %d , &u);       Chosen[u] = 1;       OnVtree[i] = u;       p[i].u = u;       p[i].dfn = dfn[u];     }     if (check()) {       for (int i = 1; i <= cnt; i++) {         int u = OnVtree[i];         Chosen[u] = 0;       }       puts( -1 );       return;     }     Get_vtree();     DP(S[1], 0);     int ans = min(d[S[1]][0], d[S[1]][1]);     printf( %d n , ans);     for (int i = 1; i <= cnt; i++) {       int u = OnVtree[i];       G[u].clear();       Chosen[u] = 0;     }   }   int main() {     scanf( %d , &n);     Init();     scanf( %d , &m);     while (m--) {       Solve();     }   }   