#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		for (auto i : boost::irange(0, 63))
		{
			if (p & (1ULL << i))
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<std::uint64_t Mod>class modnum :
		private boost::addable<modnum<Mod>>,
		private boost::subtractable<modnum<Mod>>,
		private boost::multipliable<modnum<Mod>>,
		private boost::dividable<modnum<Mod>>
	{
		std::uint64_t val;
		void clamp()
		{
			val %= Mod;
		}
	public:
		modnum() = default;
		modnum(std::int64_t v) :val()
		{
			if (v < 0)
			{
				v += (std::abs(v) / Mod + 1) * Mod;
			}
			val = v;
			clamp();
		}
		modnum(std::uint64_t v) :val(v)
		{
			clamp();
		}
		modnum(std::int32_t v) :modnum(static_cast<std::int64_t>(v))
		{

		}
		modnum(std::uint32_t v) :modnum(static_cast<std::uint64_t>(v))
		{

		}
		friend std::ostream& operator<<(std::ostream& os, modnum const& num)
		{
			return os << num.val;
		}
		auto& operator+=(modnum const& rhs)
		{
			val += rhs.val;
			clamp();
			return *this;
		}
		auto& operator-=(modnum const& rhs)
		{
			val += Mod - rhs.val;
			clamp();
			return *this;
		}
		auto& operator*=(modnum const& rhs)
		{
			val *= rhs.val;
			clamp();
			return *this;
		}
		auto& operator/=(modnum const& rhs)
		{
			val *= pow(rhs, Mod - 2).val;
			clamp();
			return *this;
		}
		auto const& operator*()const
		{
			return val;
		}
	};
}
using mod_t = lib::modnum<1000000007>;

class memoization_t
{
	std::vector<mod_t> value;
	std::vector<std::set<index_t>> child;
	index_t base;
	mod_t run(index_t i)
	{
		auto ret = value.at(child[i].size());
		for (auto c : child[i])
		{
			ret *= run(c);
		}
		return ret;
	}
public:
	memoization_t(index_t N, index_t K, std::vector<std::set<index_t>>const& edge) :value(K), child(N), base(K)
	{
		value[0] = 1;
		for (auto i : boost::irange<index_t>(1, K))
		{
			value[i] = value[i - 1] * (K - i - 1);
		}
		boost::dynamic_bitset<> flag(N);
		std::queue<index_t> queue;
		queue.emplace(0);
		while (queue.size())
		{
			auto i = queue.front();
			queue.pop();
			flag[i] = true;
			for (auto n : edge[i])
			{
				if (!flag[n])
				{
					child[i].emplace(n);
					queue.emplace(n);
				}
			}
		}
	}
	memoization_t(memoization_t const&) = delete;
	memoization_t(memoization_t&&) = delete;

	auto operator()()
	{
		auto ret = base * (base - 1) * value.at(child[0].size() - 1);
		for (auto c : child[0])
		{
			ret *= run(c);
		}
		return ret;
	}
};


void Main()
{
	index_t N, K;
	std::cin >> N >> K;
	std::vector<std::set<index_t>> edge(N);
	for (auto i : boost::irange<index_t>(0, N - 1))
	{
		index_t a, b;
		std::cin >> a >> b;
		--a; --b;
		edge[a].emplace(b);
		edge[b].emplace(a);
	}
	if (N == 1)
	{
		std::cout << K << std::endl;
	}
	else
	{
		memoization_t func(N, K, edge);
		try
		{
			std::cout << func() << std::endl;
		}
		catch (std::exception& exp)
		{
			std::cout << 0 << std::endl;
		}
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 25856