#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

void input() {}
template <class T, class... Ts> void input(T &a, Ts &... as) {
  cin >> a;
  input(as...);
}
template <class V> istream &operator>>(istream &i, vector<V> &a) {
  for (auto &e : a)
    i >> e;
  return i;
}

void print() { cout << endl; }
template <class T> void print(T const &a) { cout << a << endl; }
template <class T, class... Ts> void print(T const &a, Ts const &... as) {
  cout << a << " ";
  print(as...);
}
template <class F, class S>
ostream &operator<<(ostream &o, pair<F, S> const &pair) {
  return o << "(" << pair.first << " : " << pair.second << ")";
}
template <size_t I, size_t N, class... Ts> struct OutTuple;
template <> struct OutTuple<1, 0> {
  ostream &operator()(ostream &o, tuple<> const &t) { return o; }
};
template <size_t N, class... Ts> struct OutTuple<N, N, Ts...> {
  ostream &operator()(ostream &o, tuple<Ts...> const &t) {
    return o << get<N - 1>(t);
  }
};
template <size_t I, size_t N, class... Ts> struct OutTuple {
  ostream &operator()(ostream &o, tuple<Ts...> const &t) {
    return OutTuple<I + 1, N, Ts...>{}(o << get<I - 1>(t) << ",", t);
  }
};
template <class... Ts> ostream &operator<<(ostream &o, tuple<Ts...> const &t) {
  return OutTuple<1, sizeof...(Ts), Ts...>{}(o << "(", t) << ")";
}
template <class C> ostream &outContainer(ostream &o, C const &a) {
  o << "[";
  for (auto i = a.begin(), e = a.end(); i != e; o << ((++i != e) ? "," : ""))
    o << *i;
  return o << "]";
}
template <class V> ostream &operator<<(ostream &o, list<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, vector<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, set<V> const &a) {
  return outContainer(o, a);
}
template <class V> ostream &operator<<(ostream &o, unordered_set<V> const &a) {
  return outContainer(o, a);
}
template <class K, class V>
ostream &operator<<(ostream &o, map<K, V> const &a) {
  return outContainer(o, a);
}
template <class K, class V>
ostream &operator<<(ostream &o, unordered_map<K, V> const &a) {
  return outContainer(o, a);
}

template <size_t I, size_t N, class... Ts> struct Hash;
template <> struct Hash<1, 0> {
  size_t operator()(size_t h, tuple<> const &t) { return h; }
};
template <size_t N, class... Ts> struct Hash<N, N, Ts...> {
  size_t operator()(size_t h, tuple<Ts...> const &t) {
    auto e = get<N - 1>(t);
    return h * 31 + hash<decltype(e)>{}(e);
  }
};
template <size_t I, size_t N, class... Ts> struct Hash {
  size_t operator()(size_t h, tuple<Ts...> const &t) {
    auto e = get<I - 1>(t);
    return Hash<I + 1, N, Ts...>{}(h * 31 + hash<decltype(e)>{}(e), t);
  }
};
template <class... Ts> size_t compute_hash(tuple<Ts...> const &t) {
  return Hash<1, sizeof...(Ts), Ts...>{}(17, t);
}
namespace std {
template <class... Ts> struct hash<tuple<Ts...>> {
  size_t operator()(tuple<Ts...> const &t) const { return compute_hash(t); }
};
} // namespace std

using lli = long long int;
lli gcd(lli const p, lli const q) { return q == 0 ? p : gcd(q, p % q); }
lli pow(lli const a, lli const n, lli const m) {
  return (!n) ? 1 : (n & 1) ? (((a % m) * pow(a, n - 1, m)) % m) : [=] {
    lli b = pow(a, n / 2, m);
    return (b * b) % m;
  }();
}
lli inv(lli const a, lli const p) { return pow(a, p - 2, p); }
constexpr lli MOD = 1e9 + 7;

lli dfs(lli const K, unordered_map<lli, list<lli>> &edge, lli p, lli v) {
  lli prod = 1;
  auto const &l = edge[v];
  lli i = 1;
  for (auto const &u : l) {
    if (u != p) {
      ++i;
      prod *= ((K - i) * dfs(K, edge, v, u)) % MOD;
      prod %= MOD;
    }
  }
  return prod;
}
int main() {
  lli N, K;
  input(N, K);
  unordered_map<lli, list<lli>> edge;
  for (size_t i = 0; i < N - 1; i++) {
    lli a, b;
    input(a, b);
    if (edge.find(a) == edge.end())
      edge[a] = list<lli>{b};
    else
      edge[a].push_back(b);
    if (edge.find(b) == edge.end())
      edge[b] = list<lli>{a};
    else
      edge[b].push_back(a);
  }
  lli ans = K;
  lli i = 0;
  for (auto const &v : edge[1]) {
    ++i;
    ans *= ((K - i) * dfs(K, edge, 1, v)) % MOD;
    ans %= MOD;
  }
  print(ans);
}


Measured memory_bytes: 19236