import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val MOD = 1e9.toInt + 7

  val N, K = in.next().toInt
  val tree = Array.fill[List[Int]](N+1)(Nil)
  for (i <- 1 to N-1) {
    val a, b = in.next().toInt
    tree(a) = b :: tree(a)
    tree(b) = a :: tree(b)
  }

  //
  val dp = new Array[Boolean](N+1)

  val q = new Queue[Int]()
  q.enqueue(1)
  dp(1) = true

  var ans: Long = K
  var hoge = K-1
  while (!q.isEmpty) {
    val now = q.dequeue()

    for (e <- tree(now) if !dp(e)) {
      dp(e) = true
      ans *= Math.max(hoge, 0)
      ans %= MOD

      q.enqueue(e)
      hoge -= 1
    }

    hoge = K-2
  }

  println(ans)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
