#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <int T_MOD>
struct ModInt {
  static constexpr int MOD = T_MOD;
private:
  using ll = long long;
  int v;

  static int minv(int a, int m) {
    a %= m;
    if (a < 0) a += m;
    int b = m, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= t * a; swap(a, b);
      u -= t * v; swap(u, v);
    }
    assert(b == 1);
    if (u < 0) u += m;
    return u;
  }

public:

  ModInt() : v(0) {}
  template<class T> ModInt(T v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
  explicit operator int() const { return v; }
  friend std::ostream& operator << (std::ostream& out, const ModInt& n) { return out << int(n); }
  friend std::istream& operator >> (std::istream& in, ModInt& n) { ll v_; in >> v_; n = ModInt(v_); return in; }
  friend bool operator == (const ModInt& a, const ModInt& b) { return a.v == b.v; }
  friend bool operator != (const ModInt& a, const ModInt& b) { return a.v != b.v; }

  ModInt inv() const {
    ModInt res;
    res.v = minv(v, MOD);
    return res;
  }

  ModInt neg() const {
    ModInt res;
    res.v = v ? MOD - v : 0;
    return res;
  }

  ModInt operator- () const {
    return neg();
  }

  ModInt operator+ () const {
    return ModInt(*this);
  }

  ModInt& operator ++ () {
    v++;
    if (v == MOD) v = 0;
    return *this;
  }

  ModInt& operator -- () {
    if (v == 0) v = MOD;
    v --;
    return *this;
  }

  ModInt& operator += (const ModInt& o) {
    v += o.v;
    if (v >= MOD) v -= MOD;
    return *this;
  }

  ModInt& operator -= (const ModInt& o) {
    v -= o.v;
    if (v < 0) v += MOD;
    return *this;
  }

  ModInt& operator *= (const ModInt& o) {
    v = int(ll(v) * ll(o.v) % MOD);
    return *this;
  }

  ModInt& operator /= (const ModInt& o) {
    return *this *= o.inv();
  }

  friend ModInt operator ++ (ModInt& a, int) { ModInt r = a; ++a; return r; }
  friend ModInt operator -- (ModInt& a, int) { ModInt r = a; --a; return r; }
  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; }  
};

const int mod = 1000000007;
using Mint = ModInt<mod>;

Mint power(Mint x, int p) {
  Mint ans = Mint(1);
  while(p) {
    if(p & 1) {
      ans *= x;
    }
    x *= x;
    p >>= 1;
  }
  return ans;
}

const int N = int(1.1e5);
Mint fact[N], ifact[N];
vector<int> g[N];

void init() {
  fact[0] = ifact[0] = 1;
  for(int i = 1; i < N; ++i) {
    fact[i] = fact[i - 1] * i;
    ifact[i] = 1 / fact[i];
  }
}

Mint P(int n, int r) {
  if(n < r || n < 0) return 0;
  return fact[n] * ifact[n - r];
}

int ch[N];

void dfs(int u, int p) {
  ch[u] = 0;
  for(int x: g[u]) if (x != p) {
    ch[u]++;
    dfs(x, u);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  int n, k;
  cin >> n >> k;
  for(int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  dfs(0, -1);
  Mint res = k * P(k - 1, ch[0]);
  for(int i = 1; i < n; ++i) {
    res *= P(k - 2, ch[i]);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 10752