#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#include<algorithm>
#include<iostream>

using std::cout;
using std::endl;

constexpr int64_t EuclidMod(int64_t v, int64_t m){
  if(0 <= v && v < m){
    return v;
  }else if(-m <= v && v < 0){
    return v + m;
  }else{
    int64_t result = v % m;
    if(result < 0){
      result += m;
    }
    return result;
  }
}

// constexpr int64_t ModInv(int64_t a, int64_t m){
//   int64_t b = m, u = 1, v = 0;
//   while(b){
//     int64_t t = a / b;
//     a -= t * b;
//     std::swap(a, b);
//     u -= t * v;
//     std::swap(u, v);
//   }
//   EuclidMod(u, m);
//   return u;
// }

template<int64_t mod>
class ModInt{
  int64_t _value;

public:
  constexpr explicit ModInt(const int64_t x = 0): _value(x % mod){
  };

  constexpr ModInt& operator+=(const ModInt& another){
    _value += another._value;
    _value = EuclidMod(_value, mod);
    return *this;
  }

  constexpr ModInt& operator-=(const ModInt& another){
    _value -= another._value;
    _value = EuclidMod(_value, mod);
    return *this;
  }

  constexpr ModInt& operator*=(const ModInt& another){
    _value *= another._value;
    _value = EuclidMod(_value, mod);
    return *this;
  }

  // constexpr ModInt& operator/=(const ModInt& another){
  //   _value = _value * ModInv(another._value, mod);
  //   _value = EuclidMod(_value, mod);
  //   return *this;
  // }

  constexpr ModInt& operator++(){
    _value += ModInt(1);
    return *this;
  }

  constexpr ModInt operator++(int){
    ModInt tmp = *this;
    ++tmp;
    return tmp;
  }

  int64_t GetValue() const{
    return _value;
  }

};

template<int64_t mod>
constexpr ModInt<mod>
operator+(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) += right;
}

template<int64_t mod>
constexpr ModInt<mod>
operator-(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) -= right;
}

// template<int64_t mod>
// constexpr ModInt<mod>
// operator/(const ModInt<mod>& left, const ModInt<mod>& right){
//   return ModInt<mod>(left) /= right;
// }

template<int64_t mod>
constexpr ModInt<mod>
operator*(const ModInt<mod>& left, const ModInt<mod>& right){
  return ModInt<mod>(left) *= right;
}

template<int64_t mod>
std::ostream& operator<<(std::ostream& stream, const ModInt<mod>& mod_int){
  stream << mod_int.GetValue();
  return stream;
}





int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,k;
  cin>>n>>k;

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

  const int64_t MOD=1000000007;
  std::vector<bool> visited(n+1);
  visited[1]=true;
  ModInt<MOD> result(k);
  ModInt<MOD> temp(1);
  std::queue<int> bfs;
  for(int i=0;i<node[1].size();i++){
    temp*=ModInt<MOD>(k-1-i);
    bfs.push(node[1][i]);
    visited[node[1][i]]=true;
  }
  result*=temp;

  while(!bfs.empty()){
    int curr=bfs.front();
    bfs.pop();
    int perm_count=0;
    ModInt<MOD> temp_2(1);
    for(int i=0;i<node[curr].size();i++){
      if(!visited[node[curr][i]]){
        temp_2*=ModInt<MOD>(k-2-perm_count);
        perm_count++;
        bfs.push(node[curr][i]);
        visited[node[curr][i]]=true;
      }
    }
    result*=temp_2;
  }

  cout<<result<<endl;



  return 0;
}


Measured memory_bytes: 6520