#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(200010);

vector<vector<ll>> G(100010); 
vector<ll> memo(100010);
mint ans = 1;
ll N,K;

ll dfs(ll v, ll p){
    ll s;
    if(p == -1){
        s = G[v].size();
        ans *= comb(K-1,s);
    }else{
        s = G[v].size();
        ans *= comb(K-2,s-1);
        s--;
    }
    //cout << ans << endl;
    for(auto& u:G[v]){
        if(u == p) continue;
        if(memo[u] != 0) continue;
        ans *= s;
        s--;
        memo[u] = 1;
        dfs(u, v);
    }
    return 0;
}

int main(){

    cin >> N >> K;
    ll a,b;
    rep(i,N-1){
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memo[0] = 1;
    ans *= K;
    dfs(0, -1);
    cout << ans << endl;
    /*
    if(K<3 && N > 2){
        cout << 0 << endl;
        return 0;
    }else if(K<3){
        if(N==1){
            cout << K << endl;
        }else{
            cout << 2 << endl;
        }
        return 0;
    }
    /*
    queue<ll> que;
    vector<ll> dist(N,1e18);
    dist[0] = 0;
    que.push(0);
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(auto& u:G[v]){
            if(dist[u] != 1e18) continue;
            dist[u] = dist[v] + 1;
            que.push(u);
        }
    }
    vector<ll> ng(3);
    rep(i,N){
        ng[dist[i]%3]++;
    }
    mint ans = K*(K-1)*(K-2);
    /*rep(i,N){
        ans *= K;
    }
    mint tmp = K*(K-1)*(K-2);*/

}   

Measured memory_bytes: 17204