#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

template<Int Mod = 1000000007> class modint{
public:
	Int val;
	constexpr modint(const Int x = 0) : val(x % Mod) {if(val < 0) val += Mod;}
	constexpr modint operator+(const modint rhs) const {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const {
		return modint(*this) /= rhs;
	}
	constexpr modint operator-() const {
		return modint(Mod - val);
	}
	constexpr modint &operator+=(const modint rhs){
		val += rhs.val;
		if(val >= Mod) val -= Mod;
		return *this;
	}
	constexpr modint &operator-=(const modint rhs){
		if(val < rhs.val) val += Mod;
		val -= rhs.val;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs){
		val *= rhs.val;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator/=(const modint rhs){
		return *this *= inv(rhs);
	}
	constexpr modint &operator++(){
		++val;
		if(val == Mod) val = 0;
		return *this;
	}
	constexpr modint &operator--(){
		--val;
		if(val == -1) val = Mod - 1;
		return *this;
	}
	constexpr modint operator<<(const Int rhs) const {
		return modint(*this) << rhs;
	}
	constexpr modint operator>>(const Int rhs) const {
		return modint(*this) >> rhs;
	}
	constexpr modint &operator<<=(const Int rhs){
		val <<= rhs;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator>>=(const Int rhs){
		val >>= rhs;
		val %= Mod;
		return *this;
	}
	constexpr bool operator==(const modint rhs) const {
		return val == rhs.val;
	}
	constexpr bool operator!=(const modint rhs) const {
		return val != rhs.val;
	}
	constexpr bool operator<(const modint rhs) const {
		return val < rhs.val;
	}
	constexpr bool operator>(const modint rhs) const {
		return val > rhs.val;
	}
	constexpr bool operator<=(const modint rhs) const {
		return val <= rhs.val;
	}
	constexpr bool operator>=(const modint rhs) const {
		return val >= rhs.val;
	}
	friend ostream& operator<<(ostream& os, const modint<Mod>& m){
		return os << m.val;
	}
	friend istream& operator>>(istream& is, modint<Mod>& m){
		return is >> m.val;
	}
	static constexpr modint inv(modint m){
		Int a = m.val, b = Mod, u = 1, v = 0;
		while(b){
			Int t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		u %= Mod;
		if(u < 0) u += Mod;
		return modint(u);
	}
	constexpr operator Int() const {
		return val;
	}
};
using mint = modint<>;
vector<mint> fact(1, 1);
mint comb(Int n, Int r){
	if(n < 0 || r < 0 || n - r < 0) return 0;
	while(Int(fact.size()) <= n)
		fact.push_back(fact.back() * mint(fact.size()));
	return fact[n] / fact[r] / fact[n-r];
}
mint P(Int n, Int r){
	if(n < 0 || r < 0 || n - r < 0) return 0;
	while(Int(fact.size()) <= n)
		fact.push_back(fact.back() * mint(fact.size()));
	return fact[n] / fact[n-r];
}
Int n, k;
vector<vector<Int>> g, tr;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	g.resize(n);
	for(Int i=0; i<n-1; ++i){
		Int a, b;
		cin >> a >> b;
		g[a-1].push_back(b-1);
		g[b-1].push_back(a-1);
	}
	tr.resize(n);
	vector<bool> f(n, false);
	queue<Int> q;
	q.push(0);
	while(!q.empty()){
		Int p = q.front();
		q.pop();
		f[p] = true;
		for(size_t i=0; i<g[p].size(); ++i){
			Int t = g[p][i];
			if(!f[t]){
				tr[p].push_back(t);
				q.push(t);
			}
		}
	}
	Int c = 1;
//	for(Int i=0; i<n; ++i){
//		c = max<Int>(c, tr[i].size() + (i == 0 ? 1 : 2));
//		cerr << i << " " << c << "\n";
//	}
	if(c > k){
		cout << 0 << "\n";
		return 0;
	}
	mint ans(1);
	ans *= k;
	ans *= P(k-1, tr[0].size());
	for(Int i=1; i<n; ++i)
		ans *= P(k-2, tr[i].size());
	cout << ans << "\n";
//	cerr << c << "\n";
//	for(Int i=0; i<n; ++i){
//		cerr << i+1 << " :" << "\n";
//		for(size_t j=0; j<tr[i].size(); ++j)
//			cerr << tr[i][j]+1 << (" \n"[j+1==tr[i].size()]);
//	}
}

Measured memory_bytes: 11764