/* -*- coding: utf-8 -*- * * 1227.cc: No.1227 I hate ThREE - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MOD = 1000000007; /* typedef */ typedef long long ll; typedef vector vi; typedef queue qi; /* global variables */ vi nbrs[MAX_N]; int ps[MAX_N], cns[MAX_N]; int dp[MAX_N][MAX_N * 6]; /* subroutines */ inline void addmod(int &a, int b) { a = (a + b) % MOD; } inline void mulmod(int &a, int b) { a = (ll)a * b % MOD; } /* main */ int main() { int n, c; scanf("%d%d", &n, &c); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--, b--; nbrs[a].push_back(b); nbrs[b].push_back(a); } ps[0] = -1; qi q; q.push(0); while (! q.empty()) { int u = q.front(); q.pop(); int up = ps[u]; vi &nbru = nbrs[u]; for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) { int v = *vit; if (v != up) { ps[v] = u; cns[u]++; q.push(v); } } } int m = min(c, n * 6 - 5); for (int u = 0; u < n; u++) { fill(dp[u], dp[u] + m, 1); if (cns[u] == 0) q.push(u); } while (! q.empty()) { int u = q.front(); q.pop(); int up = ps[u]; if (up >= 0) { for (int i = 0; i < m; i++) { int d = 0; if (i >= 3) addmod(d, dp[u][i - 3]); if (i + 3 < m) addmod(d, dp[u][i + 3]); mulmod(dp[up][i], d); } if (--cns[up] == 0) q.push(up); } } int sum = 0; for (int i = 0; i < m; i++) addmod(sum, dp[0][i]); if (m < c) addmod(sum, (ll)dp[0][n * 3 - 2] * (c - m) % MOD); printf("%d\n", sum); return 0; }