#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

template<unsigned int MOD>
struct modcalc
{
	static_assert(MOD < std::numeric_limits<unsigned int>::max() / 4, "");

	static unsigned int add(unsigned int a, unsigned int b)
	{
		return (a + b) % MOD;
	}

	static void addeq(unsigned int& a, unsigned int b)
	{
		a = add(a, b);
	}

	static unsigned int sub(unsigned int a, unsigned int b)
	{
		return (MOD + a - b) % MOD;
	}

	static void subeq(unsigned int& a, unsigned int b)
	{
		a = sub(a, b);
	}

	static unsigned int neg(unsigned int a)
	{
		return (MOD - a) % MOD;
	}

	static void negeq(unsigned int& a)
	{
		a = neg(a);
	}

	static unsigned int mul(unsigned int a, unsigned int b)
	{
		return (static_cast<unsigned long long>(a) * static_cast<unsigned long long>(b)) % MOD;
	}

	static void muleq(unsigned int& a, unsigned int b)
	{
		a = mul(a, b);
	}

	static unsigned int pow(unsigned int a, unsigned int b)
	{
		int ret = 1;
		while (b) {
			if (b & 1)
				ret = mul(ret, a);
			a = mul(a, a);
			b >>= 1;
		}
		return ret;
	}

	// 階乗

	static std::vector<unsigned int> fac_table; // n!

	static void init_fac(unsigned int last)
	{
		fac_table.resize(last);
		fac_table[0] = 1;
		for (unsigned int i = 1; i < last; ++i) {
			fac_table[i] = mul(fac_table[i - 1], i);
		}
	}

	static unsigned int fac(unsigned int x)
	{
		return fac_table[x];
	}


	// 逆数

	static std::vector<unsigned int> inv_table; // n^-1

	static void init_inv(unsigned int last)
	{
		inv_table.resize(last);
		inv_table[0] = 0; // XXX
		inv_table[1] = 1;
		for (unsigned int i = 2; i < last; ++i) {
			inv_table[i] = MOD - mul(inv_table[MOD % i], MOD / i);
		}
	}

	static unsigned int inv(unsigned int x)
	{
		return inv_table[x];
	}

	static unsigned int div(unsigned int a, unsigned int b)
	{
		return mul(a, inv(b));
	}

	static void diveq(unsigned int a, unsigned int b)
	{
		a = div(a, b);
	}


	// 階乗の逆数

	static std::vector<unsigned int> invfac_table; // (n!)^-1

	static unsigned int init_invfac(unsigned int last)
	{
		invfac_table.resize(last);
		invfac_table[0] = 0; // XXX
		invfac_table[1] = 1;
		for (unsigned int i = 2; i < last; ++i) {
			invfac_table[i] = mul(invfac_table[i - 1], inv_table[i]);
		}
	}

	static unsigned int invfac(unsigned int x)
	{
		return invfac_table[x];
	}

	// 二項係数

	static unsigned int combination(unsigned int n, unsigned int k)
	{
		if (n < k)
			return 0;
		return mul(fac(n), mul(invfac(k), invfac(n - k)));
	}
};

template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::fac_table;
template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::inv_table;
template<unsigned int MOD> std::vector<unsigned int> modcalc<MOD>::invfac_table;

using mod = modcalc<1000000007U>;

int main()
{
	int N, K;
	std::vector<std::pair<int, int>> E;
	std::vector<std::unordered_set<int>> neighbors;

	std::cin >> N >> K;
	E.resize(N-1);
	neighbors.resize(N);
	for (auto& e : E) {
		std::cin >> e.first >> e.second;
		--e.first;
		--e.second;
		neighbors[e.first].insert(e.second);
		neighbors[e.second].insert(e.first);
	}

	std::vector<int> curneigh; // 現在のグラフにおける隣接ノードの数
	curneigh.resize(N);
	std::stack<std::pair<int, int>> stk; // BFSのスタック first:追加されるノード second:その前のノード
	unsigned int result = 1;
	stk.push({0, -1});
	while (!stk.empty()) {
		auto& t = stk.top();
		stk.pop();
		int cur = t.first;
		int subval = t.second >= 0 ? curneigh[t.second]+1 : 0;
		if (subval >= K) {
			std::cout << "0\n";
			return 0;
		}
		if (t.second >= 0) {
			++curneigh[t.first];
			++curneigh[t.second];
		}
		mod::muleq(result, (K - subval));
		for (auto n : neighbors[cur]) {
			stk.push({n,cur});
			neighbors[n].erase(cur);
		}
	}
	std::cout << result << "\n";
}


Measured memory_bytes: 18084