#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T powi(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return powi(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }

    class Factorial {
    private:
        static vector<ModInt> table[2];
    public:
        static void reserve(int n) {
            for (auto &v: table) v.resize(n+1);
            table[0][0] = 1;
            for (int i = 1; i <= n; ++i) table[0][i] = table[0][i-1].num * i;
            table[1][n] = table[0][n].inv();
            for (int i = n; i >= 1; --i) table[1][i-1] = table[1][i].num * i;
        }
    private:
        int num;
    public:
        Factorial() {};
        Factorial(int n): num(n) {};
        ModInt finv() const { return table[1][num]; }
        operator ModInt() const { return table[0][num]; }
    };
    ModInt& operator /=(const Factorial& a) { return *this *= a.finv(); }
    friend ModInt operator /(const ModInt& a, const Factorial& b) { return ModInt(a) /= b; }
};
template<ll mod>
vector<ModInt<mod>> ModInt<mod>::Factorial::table[2];

using mint = ModInt<1000000007>;
using fact = mint::Factorial;

mint P(int n, int k) {
    if (k > n) return 0;
    return fact(n) / fact(n-k);
}
mint C(int n, int k) {
    return fact(n) / fact(n-k) / fact(k);
}
mint H(int n, int k) {
    return C(n+k-1, k);
}

int n, k;

mint dfs(vector<vector<int>> &g, int v, int p) {
    if (g[v].size() == 1) return 1;
    mint ret = 1;
    for (auto u: g[v]) {
        if (p == u) continue;
        ret *= dfs(g, u, v);
    }
    ret *= P(k-2, g[v].size()-1);
    return ret;
}

int main() {
    cin >> n >> k;
    vector<vector<int>> g(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    fact::reserve(max(n, k));
    mint ans = 1;
    for (auto &v: g[0]) {
        ans *= dfs(g, v, 0);
    }
    ans *= P(k, g[0].size()+1);
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13184