func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long sum = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) {       sum = (sum << 1) + (sum << 3) + (c ^ 48);       c = getchar();     }     return sum;   }   long long const maxn = 1e5 + 5;   long long const p = 1e9 + 7;   long long n, q, a[maxn];   long long father[maxn], Dep[maxn], size[maxn], son[maxn], top[maxn], seg[maxn],       rev[maxn << 2];   long long sum_seg[maxn << 2];   long long f[maxn], sum[maxn];   struct Edge {     long long next, to;   } E[maxn << 1];   long long cnt, H[maxn];   inline void AADDDD(long long a, long long b) {     E[++cnt] = (Edge){H[a], b};     H[a] = cnt;   }   void dfs1(long long x, long long fa) {     Dep[x] = Dep[fa] + 1;     father[x] = fa;     size[x] = 1;     for (long long i = H[x]; i; i = E[i].next) {       long long y = E[i].to;       if (y == fa) continue;       dfs1(y, x);       size[x] += size[y];       if (size[y] > size[son[x]]) son[x] = y;     }   }   void dfs2(long long x, long long fa) {     if (son[x]) {       seg[son[x]] = ++seg[0];       rev[seg[0]] = son[x];       top[son[x]] = top[x];       dfs2(son[x], x);     }     for (long long i = H[x]; i; i = E[i].next) {       long long y = E[i].to;       if (!top[y]) {         seg[y] = ++seg[0];         rev[seg[0]] = y;         top[y] = y;         dfs2(y, x);       }     }   }   void change(long long k, long long l, long long r, long long x, long long v) {     if (l == r && l == x) {       sum_seg[k] += v;       return;     }     if (r < x || l > x) return;     long long mid = l + r >> 1;     change(k << 1, l, mid, x, v);     change(k << 1 | 1, mid + 1, r, x, v);     sum_seg[k] = sum_seg[k << 1] + sum_seg[k << 1 | 1];   }   long long query(long long k, long long l, long long r, long long x,                   long long y) {     if (l >= x && r <= y) return sum_seg[k];     if (r < x || l > y) return 0;     long long mid = l + r >> 1;     return query(k << 1, l, mid, x, y) + query(k << 1 | 1, mid + 1, r, x, y);   }   inline long long ask(long long x, long long y) {     long long res = 0;     while (top[x] != top[y]) {       if (Dep[top[x]] < Dep[top[y]]) swap(x, y);       res += query(1, 1, seg[0], seg[top[x]], seg[x]);       x = father[top[x]];     }     if (Dep[x] > Dep[y]) swap(x, y);     res += query(1, 1, seg[0], seg[x], seg[y]);     return res;   }   signed main() {     n = read(), q = read();     for (long long i = 1; i < n; i++) {       long long x = read(), y = read();       AADDDD(x, y), AADDDD(y, x);     }     dfs1(1, 0);     seg[0] = seg[1] = 1;     top[1] = 1, rev[1] = 1;     dfs2(1, 0);     while (q--) {       long long k = read(), m = read(), r = read();       for (long long i = 1; i <= k; i++) {         a[i] = read();         change(1, 1, seg[0], seg[a[i]], 1);       }       for (long long i = 1; i <= k; i++) sum[i] = ask(a[i], r) - 1;       bool wujie = false;       for (long long i = 1; i <= sum[i]; i++)         if (sum[i] >= m) wujie = true;       sort(sum + 1, sum + k + 1);       for (long long i = 1; i <= k; i++) f[i] = 0;       f[0] = 1;       for (long long i = 1; i <= k; i++)         for (long long j = min(i, m); j >= 0; j--) {           if (j <= sum[i])             f[j] = 0;           else             f[j] = (f[j - 1] + f[j] * (j - sum[i]) % p) % p;         }       long long ans = 0;       for (long long i = 1; i <= m; i++) ans = (ans + f[i]) % p;       if (wujie)         printf( 0 n );       else         printf( %lld n , ans);       for (long long i = 1; i <= k; i++) change(1, 1, seg[0], seg[a[i]], -1);     }     return 0;   }   