class Integer
  def combination(k)
    return 1 if k.zero?

    (self - k + 1 .. self).inject(:*) / k.factorial
  end

  def permutation(k)
    return 1 if k.zero?

    (self - k + 1 .. self).inject(:*)
  end

  def factorial
    return 1 if self.zero?

    (1 .. self).inject(:*)
  end
end

MOD = 10 ** 9 + 7

$n, $k = gets.chomp.split.map(&:to_i)
$edge  = Array.new($n).map { Array.new() }

($n - 1).times do
  a, b = gets.chomp.split.map(&:to_i).map(&:pred)
  $edge[a] << b;
  $edge[b] << a;
end


$ans = 1

stack   = [0]
visited = [false] * $n

while (!stack.empty?)
  i          = stack.pop
  visited[i] = true
  if i == 0
    $ans = $k.permutation($edge[0].size + 1)
  else
    $ans *= ($k - 2).permutation($edge[i].size - 1)
  end
  $ans %= MOD
  $edge[i].each do |v|
    next if visited[v] == true
    stack << v
  end
end

puts $ans



