#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール
// 剰余演算
constexpr ll p = 1000000007LL; // 10^9+7
ll powll(ll a, ll n) {
    if (n == 0) {
        return 1LL;
    } else if (n == 1) {
        return a % p;
    } else {
        ll temp = powll(a, n/2);
        temp = temp * temp % p;
        return n % 2 ? temp * a % p : temp;
    }
}

inline ll invll(ll a) { return powll(a, p-2); }

vector<ll> fac_cache = {1}, invfac_cache = {1};
void make_fac_cache(ll a) {
    ll old_max = fac_cache.size() - 1;
    if (a > old_max) {
        fac_cache   .resize(a+1);
        invfac_cache.resize(a+1);
        for (ll i = old_max + 1; i <= a; i++) {
            fac_cache[i] = fac_cache[i-1] * i % p;
        }
        invfac_cache[a] = invll(fac_cache[a]);
        for (ll i = a-1; i > old_max; i--) {
            invfac_cache[i] = invfac_cache[i+1] * (i + 1) % p;
        }
    }
}

inline ll    facll(ll a) { make_fac_cache(a); return fac_cache[a]; }
inline ll invfacll(ll a) { make_fac_cache(a); return invfac_cache[a]; }
inline bool isoutll(ll n, ll r) { return n < 0 || r < 0 || n < r; }
inline ll nPr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p; }
inline ll nCr(ll n, ll r) { return isoutll(n, r) ? 0 : facll(n) * invfacll(n-r) % p * invfacll(r) % p; }
inline ll nHr(ll n, ll r) { return nCr(n+r-1, r); }

// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;
    vector<vector<ll>> g(n);
    vector<ll> deg(n, 0);
    REP(i, n-1) {
        ll a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }

    // BFS -- scale the depths and identify the parents
    vector<ll> d(n, -1), par(n, -1);
    deque<ll> q = {0};
    d[0] = 0;
    while (q.size()) {
        ll v = q.front(); q.pop_front();
        for (ll u : g[v]) {
            if (d[u] == -1) {
                d[u] = d[v] + 1;
                par[u] = v;
                q.push_back(u);
            }
        }
    }

    vector<ll> toori(n);
    vector<ll> nutta_children(n, 0);
    REP(i, n) {
        ll parent = par[i];
        ll grand_parent = parent == -1 ? -1 : par[parent];
        if (parent == -1) { // root
            toori[i] = k;
        } else if (grand_parent == -1) { // semi-root
            ll nutta_family = nutta_children[parent] + 1;
            nutta_children[parent]++;
            toori[i] = k - nutta_family;
        } else { // non-root
            ll nutta_family = nutta_children[parent] + 2;
            nutta_children[parent]++;
            toori[i] = k - nutta_family;
        }
    }

    ll ans = 1;
    REP(i, n) (ans *= toori[i]) %= p;
    cout << ans << endl;
    
}

Measured memory_bytes: 11544