#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

//負数の合同も考慮に入れるmod関数
inline long long imod(long long a, long long b)
{
	return (a >= 0) ? (a % b) : (a % b + b);
}

//mintが引数の繰り返し2乗法
class mint;
mint pow(mint x, long long n);

//modの整数クラス
class mint
{
public:
	static void set_mod(long long m_)
	{
		//無効な値は無視
		if (m_ < 2)return;
		//modの値を更新
		mod = m_;
		//オイラー関数Φ(mod)を計算する
		e_phi = m_;
		for (int i = 2; i * i <= m_; ++i)
		{
			if (m_ % i == 0)
			{
				e_phi = e_phi / i * (i - 1);
				for (; m_ % i == 0; m_ /= i);
			}
		}
		if (m_ != 1)e_phi = e_phi / m_ * (m_ - 1);
	}
	mint operator+(const mint & other)const
	{
		return mint(a + other.a >= mod ? a + other.a - mod : a + other.a, true);
	}
	mint operator-(const mint & other)const
	{
		return mint(a - other.a < 0 ? a - other.a + mod : a - other.a, true);
	}
	mint operator*(const mint & other)const
	{
		return mint(imod(a * other.a, mod));
	}
	mint operator+=(const mint & other)
	{
		a = a + other.a >= mod ? a + other.a - mod : a + other.a;
		return mint(a, true);
	}
	mint operator-=(const mint & other)
	{
		a = a - other.a < 0 ? a - other.a + mod : a - other.a;
		return mint(a, true);
	}
	mint operator*=(const mint & other)
	{
		a = imod(a * other.a, mod);
		return mint(a);
	}
	mint operator+()const
	{
		return *this;
	}
	mint operator-()const
	{
		return mint(mod - a >= mod ? -a : mod - a, true);
	}
	mint& operator++()
	{
		*this += 1;
		return *this;
	}
	mint operator++(int)
	{
		auto tmp = *this;
		*this += 1;
		return tmp;
	}
	mint& operator--()
	{
		*this -= 1;
		return *this;
	}
	mint operator--(int)
	{
		auto tmp = *this;
		*this -= 1;
		return tmp;
	}
	mint operator~()const
	{
		return pow(*this, e_phi - 1);
	}
	mint& operator=(const mint & other)
	{
		a = other.a;
		return *this;
	}
	operator long long()const
	{
		return a;
	}
	explicit operator int()const
	{
		return (int)a;
	}
	static long long getmod()
	{
		return mod;
	}
	mint(long long a_) :a(imod(a_, mod)) {}
	mint() :a(0) {}
private:
	static long long mod;
	static long long e_phi;
	long long a;
	mint(long long a_, bool) : a(a_) {}
};

//mintの累乗
//x^nを計算します
mint pow(mint x, long long n)
{
	mint res = 1;
	while (n > 0)
	{
		if (n & 1)res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

#include <vector>
mint minv[3333];

//mintの階乗計算
//O(x)程度の時間がかかります
//非推奨、同時間でfact_setが計算可能
mint fact(mint x)
{
	mint res(1);
	for (long long i = 1; i <= (long long)x; ++i)
	{
		res *= i;
	}
	return res;
}

//mintの階乗計算のリスト
//setの末尾に0～xまでの階乗数の列挙をします
//O(x)程度の時間がかかります
void fact_set(std::vector<mint> & set, mint x = mint(-1))
{
	mint res(1);
	set.push_back(1);
	for (long long i = 1; i <= (long long)x; ++i)
	{
		res *= i;
		set.push_back(res);
	}
}

long long mint::mod = 1000000000 + 7;
long long mint::e_phi = mod - 1;

#include<iostream>

//mint型のstreamへの入出力対応
std::ostream& operator<<(std::ostream & os, mint i)
{
	os << (long long)i;
	return os;
}

std::istream& operator >> (std::istream & is, mint & i)
{
	long long tmp;
	is >> tmp;
	i = tmp;
	return is;
}

LL N, K;
mint kk1;
vector<int>G[123456];

mint dp(int x, int las) {
	mint res = K;
	int j = 1;
	for (int ch : G[x]) {
		if (ch == las)continue;
		mint fac = dp(ch, x);
		int i = (int)G[ch].size();
		fac *= K - j;
		fac *= K - i;
		fac *= kk1;
		j++;
		res *= fac;
	}
	return res;
}

int main() {
	cin >> N >> K;
	kk1 = ~mint(K) * ~mint(K - 1);
	for (int i = 1; i < N; i++) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cout << dp(0, -1) << endl;
}


Measured memory_bytes: 12160