// {{{ Templates #include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; template constexpr T INF = numeric_limits::max() / 100; // }}} int N; struct Graph { Graph(const int n) { edge.resize(n); } void addEdge(const int from, const int to) { edge[from].push_back(to); } vector> edge; }; struct Polynomial { Polynomial() : coeff(N + 1, 0), degree(0) {} static Polynomial monomial(const ll coe, const int deg) { Polynomial p; p.coeff[deg] = coe; p.degree = deg; return p; } Polynomial operator+(const Polynomial& p) const { Polynomial P; if (degree >= p.degree) { for (int i = 0; i <= p.degree; i++) { P.coeff[i] = (coeff[i] + p.coeff[i]) % MOD; } } else { for (int i = 0; i <= degree; i++) { P.coeff[i] = (coeff[i] + p.coeff[i]) % MOD; } for (int i = degree + 1; i <= p.degree; i++) { P.coeff[i] = p.coeff[i]; } } P.degree = max(degree, p.degree); return (*this); } Polynomial& operator+=(const Polynomial& p) { if (degree >= p.degree) { for (int i = 0; i <= p.degree; i++) { coeff[i] += p.coeff[i]; coeff[i] = coeff[i] % MOD; } } else { for (int i = 0; i <= degree; i++) { coeff[i] += p.coeff[i]; coeff[i] = coeff[i] % MOD; } for (int i = degree + 1; i <= p.degree; i++) { coeff[i] = p.coeff[i]; coeff[i] = coeff[i] % MOD; } } degree = max(degree, p.degree); return (*this); } Polynomial operator*(const Polynomial& p) const { Polynomial P; P.degree = degree + p.degree; for (int i = 0; i <= P.degree; i++) { ll sum = 0; for (int j = 0; j <= min(degree, i); j++) { sum = (sum + coeff[j] * p.coeff[i - j] % MOD) % MOD; } P.coeff[i] = sum; } return P; } int degree = 0; vector coeff; }; ostream& operator<<(ostream& os, const Polynomial& p) { for (int i = 0; i <= p.degree; i++) { if (i > 0) { os << " + "; } os << p.coeff[i]; if (i > 0) { os << "x^" << i; } } os << endl; return os; } int size_dfs(const Graph& g, const int s, vector& size) { int num = 1; for (const int to : g.edge[s]) { num += size_dfs(g, to, size); } size[s] = num; return num; } Polynomial dp_dfs(const Graph& g, const int s, const vector& size) { Polynomial P = Polynomial::monomial(1LL, size[s]); Polynomial Product = Polynomial::monomial(1LL, 0); for (const int to : g.edge[s]) { Product = Product * dp_dfs(g, to, size); } P += Product; return P; } int main() { cin.tie(0); ios::sync_with_stdio(false); int K; cin >> N >> K; Graph g(N); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; g.addEdge(a, b); } vector size(N, 0); size_dfs(g, 0, size); cout << dp_dfs(g, 0, size).coeff[K] << endl; return 0; }