#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <algorithm>
#include <initializer_list>
#include <utility>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using ll = long long;

int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
double sd() { double x; scanf("%lf", &x); return x; }
char sc() { char x; while (isspace(x = getchar())); return x; }
void newline() { putchar('\n'); }
void space() { putchar(' '); }
void print(int x) { printf("%d", x); }
void print(long long x) { printf("%lld", x); }
void print(double x) { printf("%.15f", x); }
void print(const char *s) { printf("%s", s); }
template<class T> void println(const T &x) { print(x); putchar('\n'); }
template<class T, class... TS> void print(const T &x, TS ...xs) { print(x); space(); print(xs...); }
template<class... TS> void println(TS ...xs) { print(xs...); newline(); }

template<class T>
struct vec {
  int n;
  T *a;
  explicit vec(int n_) : n(n_), a(new T[n_]) {}
  vec(std::initializer_list<T> xs) : n(xs.size()), a(new T[a.size()]) { int i = 0; for (T x : xs) a[i++] = x; }
  ~vec() { if (a) delete[] a; }
  vec(const vec<T> &a) = delete;
  vec(vec<T> &&a) : n(a.n), a(a.a) { a.a = nullptr; puts("move"); }
  vec<T> &operator=(const vec<T> &a) = delete;
  T &operator[](int i) { assert(0 <= i && i < n); return a[i]; }
  int size() const { return n; }
  vec<T> clone() {
    vec<T> res(n);
    for (int i = 0; i < n; i++) res.a[i] = a[i];
    return res;
  }
  void sort() { std::sort(a, a + n); }
  template<class F> void sort_by(F f) { std::sort(a, a + n, f); }
  friend void print(const vec<T> &a) {
    putchar('[');
    for (int i = 0; i < a.size(); i++) {
      if (i != 0) putchar(',');
      print(a.a[i]);
    }
    putchar(']');
  }
  template<class X, class F> vec<T> map(F f) {
    vec<X> res(n);
    for (int i = 0; i < n; i++) res.a[i] = f(a[i]);
    return res;
  }
  template<class X, class F> vec<X> mapi(F f) {
    vec<X> res(n);
    for (int i = 0; i < n; i++) res.a[i] = f(i, a[i]);
    return res;
  }
  template<class X, class F> X fold_left(F f, X x) {
    for (int i = 0; i < n; i++) x = f(x, a[i]);
    return x;
  }
};

template<class T>
struct mat {
  int n, m;
  T *a;
  explicit mat(int n_, int m_) : n(n_), m(m_), a(new T[n_ * m_]) {}
  ~mat() { if (a) delete[] a; }
  mat(const mat<T> &a) = delete;
  mat(mat<T> &&a) : n(a.n), m(a.m), a(a.a) { a.a = nullptr;}
  mat<T> &operator=(const vec<T> &a) = delete;
  T &operator()(int i, int j) { assert(0 <= i && i < n && 0 <= j && j < m); return a[i * m + j]; }
  mat<T> clone() {
    mat<T> res(n, m);
    for (int i = 0; i < n * m; i++) {
      res.a[i] = a[i];
    }
    return res;
  }
};

template<class T>
struct darray {
  int n;
  int c;
  T *a;
  darray() : n(0), c(1), a(new T[1]) {}
  darray(const darray<T> &a) = delete;
  darray(darray<T> &&a) : n(a.n), c(a.c), a(a.a) { a.a = nullptr; }
  ~darray() { if (a) delete[] a; }
  darray<T> operator=(const darray<T> &a) = delete;
  T &operator[](int i) { assert(0 <= i && i < n); return a[i]; }
  int size() const { return n; }
  void push(const T &v) {
    if (n == c) {
      c *= 2;
      T *a_ = new T[c];
      for (int i = 0; i < n; i++) a_[i] = std::move(a[i]);
      delete[] a;
      a = a_;
    }
    a[n++] = v;
  }
  T pop() { assert(n > 0); return a[--n]; }
  void sort() { std::sort(a, a + n); }
  template<class F> void sort_by(F f) { std::sort(a, a + n, f); }
  darray<T> clone() {
    darray<T> res;
    res.n = n;
    res.c = n;
    res.a = new T[c];
    for (int i = 0; i < c; i++) {
      res.a[i] = a[i];
    }
    return res;
  }
  template<class F> void each(F f) {
    for (int i = 0; i < n; i++) f(a[i]);
  }
  friend void print(const darray<T> &v) {
    putchar('[');
    for (int i = 0; i < v.n; i++) {
      if (i != 0) putchar(',');
      print(v.a[i]);
    }
    putchar(']');
  }
};

const int MOD = 1000000007;
 
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
void print(mint a) { print(a.n); }

darray<mint> F_, R_, I_;
 
void check_fact(int n) {
  if (I_.size() == 0) {
    I_.push(0); I_.push(1);
    F_.push(1); F_.push(1);
    R_.push(1); R_.push(1);
  }
  for (int i = I_.size(); i <= n; i++) {
    I_.push(I_[MOD % i] * (MOD - MOD / i));
    F_.push(F_[i - 1] * i);
    R_.push(R_[i - 1] * I_[i]);
  }
}
 
mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[-n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
 
 
int main() {
  int N = si(), K = si();
  vec<int> deg(N);
  rep(i, N-1) {
    int u = si()-1, v = si()-1;
    deg[u]++;
    deg[v]++;
  }
  mint ans = deg.mapi<mint>([K](int i, int x) {
    return i==0 ? P(K, x+1) : P(K-2, x-1);
  }).fold_left([](mint x, mint y) { return x * y; }, mint(1));
  println(ans);
}

Measured memory_bytes: 3056