#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;
const int MAX=1e5+100;

struct Permutation {
  vector<ll> fac,inv,finv;
  
  Permutation() : fac(MAX),inv(MAX),finv(MAX) {
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    FOR(i,2,MAX) {
      fac[i] = fac[i-1]*i%MOD;
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
      finv[i] = finv[i-1]*inv[i]%MOD;
    }
  }

  int calc(int n, int k) {
    return fac[n]*finv[n-k]%MOD;
  }
};

Permutation p = Permutation();
int K;

ll dfs(int curidx, int from, vector<vector<int>> &G) {
  if (siz(G[curidx])==1) return 1;
  if (siz(G[curidx])-1>K-2) {
    OUT(0);
    exit(0);
  }

  ll ret = p.calc(K-2,siz(G[curidx])-1);
  for (auto idx:G[curidx]) {
    if (idx==from) continue;
    ret = ret*dfs(idx,curidx,G)%MOD;
  }
  return ret;
}

int main() {
  int N;cin>>N>>K;

  vector<vector<int>> G(N);
  REP(i,N-1) {
    int a,b;cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // 最もそこから島が繋がっているところから始める
  int starter_idx = 0;
  REP(i,N) {
    if(siz(G[i])>siz(G[starter_idx])) starter_idx = i;
  }

  // 塗り分け不可(starter_idxから伸びる線がK-1いない)
  if (siz(G[starter_idx])>K-1) {
    OUT(0);
    return 0;
  }

  // 最初はK通り
  ll ans = K;
  // 第二階層
  ans = ans*p.calc(K-1,siz(G[starter_idx]))%MOD;

  // 第三階層行こう
  for (auto idx:G[starter_idx]) {
    ans = ans*dfs(idx,starter_idx,G)%MOD;
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 13952