#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
    if(flg) {
        cout << hoge << endl;
        exit(0);
    }
}
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if(a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if(a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while(exp) {
            if(exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using mint = modint<MOD>;
mint ANS=1;
vector<mint> kaijo(100001);
struct tree {
    vector<vector<ll>> G;
    ll N;
    vl visited;
    void init(ll n) {
        N = n;
        G.resize(N);
        visited = vl(N, 0);
    }

    void add(ll a, ll b) { G[a].push_back(b); }

    void resetv(void) { visited = vl(N, 0); }

    vl par, toposo, ko;
    void root(ll x) {
        par = vl(N, -1);
        ko = vl(N, 0);
        dfs_tree(x);

        reverse(all(toposo));

        rep(i,N){
            ll a=toposo[i];
            if(i==0)ANS=k;
            else if(par[a]==0)ANS*=k-1-ko[0];
            else ANS*=k-2-ko[par[a]];
            if(i!=0)ko[par[a]]++;
        }

        cout<<ANS.a<<endl;

    }
    void dfs_tree(ll x) {
        visited[x] = 1;
        for(ll i : G[x]) {
            if(visited[i] == 0) {
                dfs_tree(i);
                par[i] = x;
                //ko[x]++;
            }
        }
        toposo.push_back(x);
    }

};

int main() {
    cin>>n>>k;
    kaijo[0]=1;
    rep(i,n){
        kaijo[i+1]=kaijo[i]*(i+1);
    }

    tree T;
    T.init(n);

    rep(i,n-1){
        cin>>a>>b;
        a--;
        b--;
        T.add(a,b);
        T.add(b,a);
    }

    T.root(0);
}

Measured memory_bytes: 12664