// https://atcoder.jp/contests/abc133/tasks/abc133_f

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

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

template <int mod> struct ModInt {
    static const int Mod = mod;
    unsigned x;
    ModInt() : x(0) {}
    ModInt(signed sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % mod + mod : sig % mod; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) {
        if ((x += that.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(ModInt that) {
        if ((x += mod - that.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator*=(ModInt that) {
        x = (unsigned long long)x * that.x % mod;
        return *this;
    }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const {
        long long a = x, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            std::swap(a, b);
            u -= t * v;
            std::swap(u, v);
        }
        return ModInt(u);
    }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const {
        ModInt t;
        t.x = x == 0 ? 0 : Mod - x;
        return t;
    }
};
template <int mod> ostream &operator<<(ostream &st, const ModInt<mod> a) {
    st << a.get();
    return st;
};
template <int mod> ModInt<mod> operator^(ModInt<mod> a, unsigned long long k) {
    ModInt<mod> r = 1;
    while (k) {
        if (k & 1)
            r *= a;
        a *= a;
        k >>= 1;
    }
    return r;
}
typedef ModInt<MOD> mint;

int n, k;
vector<vector<int>> v;

mint dfs(int now, int from) {
    mint ret = 1;
    ll cnt = (from == -1 ? k - 1 : k - 2);
    for (auto x : v[now]) {
        if (from != x) {
            ret *= dfs(x, now);
            ret *= (cnt--);
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    mint ans = dfs(0, -1) * k;
    cout << ans.get() << endl;

    return 0;
}


Measured memory_bytes: 11648