func_code_string: #include <bits/stdc++.h>   using namespace std;   long long mod = (long long)1000000007;   int M, K;   int par[100000 + 5];   vector<int> adj[100000 + 5];   long long dp[100000 + 5][11][3];   struct bin_tree_type {     int le;     int ri;   };   bin_tree_type tree[100000 + 5];   long long exp(long long ret, int pow) {     if (pow == 0) {       return 1;     }     long long sav = 1;     while (pow ^ 1) {       if (pow & 1) {         sav *= ret;         sav %= mod;       }       pow >>= 1;       ret *= ret;       ret %= mod;     }     ret *= sav;     ret %= mod;     return ret;   }   long long inv(long long inp) { return exp(inp, mod - 2); }   void dfs_lcrs(int nod, int pt) {     int lastchild = -1;     par[nod] = pt;     for (int ke : adj[nod]) {       if (ke == pt) {         continue;       }       if (lastchild == -1) {         tree[nod].le = ke;       } else {         tree[lastchild].ri = ke;       }       dfs_lcrs(ke, nod);       lastchild = ke;     }   }   long long DP(int nod, int rem, int status) {     if (nod == 0) {       if (rem == 0) {         return 1;       } else {         return 0;       }     }     long long &ret = dp[nod][rem][status];     if (ret >= 0) {       return ret;     }     ret = 0;     if (rem && status != 2) {       if (status == 1) {         long long sumc = 0;         for (int i = 0; i <= rem - 1; i++) {           sumc += DP(tree[nod].le, i, 2) * DP(tree[nod].ri, rem - 1 - i, 1);           sumc %= mod;         }         ret += sumc;       } else {         long long mult;         if (nod != 1) {           mult = ((long long)(K - 1) * inv(M - 1)) % mod;         } else {           mult = 1;         }         long long sumc = 0;         for (int i = 0; i <= rem - 1; i++) {           sumc += DP(tree[nod].le, i, 2) * DP(tree[nod].ri, rem - 1 - i, 1);           sumc %= mod;         }         sumc *= mult;         sumc %= mod;         ret += sumc;       }     }     if (status == 0) {       long long mult = M - 1;       long long sumc = 0;       for (int i = 0; i <= rem; i++) {         sumc += DP(tree[nod].le, i, 0) * DP(tree[nod].ri, rem - i, 0);         sumc %= mod;       }       sumc *= mult;       sumc %= mod;       ret += sumc;     } else if (status == 1) {       long long mult = M - 1;       long long sumc = 0;       for (int i = 0; i <= rem; i++) {         sumc += DP(tree[nod].le, i, 0) * DP(tree[nod].ri, rem - i, 1);         sumc %= mod;       }       sumc *= mult;       sumc %= mod;       ret += sumc;     } else if (status == 2) {       long long mult = K - 1;       long long sumc = 0;       for (int i = 0; i <= rem; i++) {         sumc += DP(tree[nod].le, i, 1) * DP(tree[nod].ri, rem - i, 2);         sumc %= mod;       }       sumc *= mult;       sumc %= mod;       ret += sumc;     }     return ret;   }   int main() {     memset(dp, -1, sizeof(dp));     int N, a, b, X;     long long has = 0;     scanf( %d %d , &N, &M);     int edge = N - 1;     while (edge--) {       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     scanf( %d %d , &K, &X);     if (K == 1 && N > 1) {       printf( %lld n , exp(M - 1, N));       return 0;     }     dfs_lcrs(1, 1);     for (int i = X; i >= 0; i--) {       has += DP(1, i, 0);       has %= mod;     }     printf( %lld n , has);   }   