#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;

//////////////////////////////////////////////////////////////////////

#define MAX_P 100000
const long long mod = 1000000007;
class combination {
public:
	ll fact[MAX_P]; // n! mod pのテーブル(O(p))
	ll p;
	// factテーブルを初期化する
	combination(ll x) {  // x : 余り(1e9 + 7など)
		p = x;
		fact[0] = 1;
		for (ll i = 1; i < MAX_P; i++) {
			fact[i] = fact[i - 1] * i % p;
		}
	}
	//拡張ユークリッドの互除法
	ll extgcd(ll a, ll b, ll& x, ll& y) {
		ll d = a;
		if (b != 0) {
			d = extgcd(b, a%b, y, x);
			y -= (a / b) * x;
		}
		else {
			x = 1; y = 0;
		}
		return d;
	}
	//mod上の逆元
	ll mod_inverse(ll a, ll m) {
		ll x, y;
		extgcd(a, m, x, y); //extgcdが必要
		return (m + x % m) % m;
	}
	//n! = a p^eとしたときの a mod pを求める O(log_p a)
	ll mod_fact(ll n, ll p, ll& e) {
		e = 0;
		if (n == 0) return 1;

		//pの倍数の部分を計算
		ll res = mod_fact(n / p, p, e);
		e += n / p;

		//(p - 1)!≡-1なので、(p-1)!^(n/p)はn/pの偶奇だけで計算できる
		if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
		return res * fact[n % p] % p;
	}

	//mod p 上の二項係数
	ll mod_comb(ll n, ll k) {
		if (n < 0 || k < 0 || n < k) return 0;
		ll e1, e2, e3;
		ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n - k, p, e3);
		if (e1 > e2 + e3) return 0;
		return a1 * mod_inverse(a2 * a3 % p, p) % p;
	}
};
ll cal(ll a, ll b) {
	if (b < 1) return 1;
	if (b == 1) return a % mod;
	else return a * cal(a - 1, b - 1) % mod;
}
int main(void) {
	//debug(cal(6,3));
	combination c(mod);
	ll n, k; cin >> n >> k;
	vvi G(n, vi(0));
	vi p(n, 1);
	vector<bool> used(n, false);
	rep(n - 1) {
		ll a, b; cin >> a >> b;
		a--, b--;
		G[a].pb(b);
		G[b].pb(a);
	}

	//0を根としてBFSしましょう
	queue<ll> q;
	ll b = 1;
	q.push(0);
	ll ans = 1LL;
	while (!q.empty()) {
		ll x = q.front();
		used[x] = true;
		q.pop();// debug(x);
		ll s = G[x].size();
		rep(s) {
			if (used[G[x][i]]) continue;
			q.push(G[x][i]);
			used[G[x][i]] = true;
		}
		if (b == 1) {
			p[0] = cal(k, s + 1);
			b *= 0;
		}
		else {
			p[x] = cal(k - 2, s - 1);
		}
	}
	rep(n) {
		ans *= p[i];
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9716