MOD = 1000000007
n, k = gets.split.map(&:to_i)
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
edges.each do |from, to|
  graph[from] << to
  graph[to] << from
end
ans = [k]
colors = k - 1
#[from, to]
queue = [[1, 1]]
until queue.empty?
  from, current = queue.shift
  rest = colors
  graph[current].each do |to|
    next if from == to
    ans << rest
    rest -= 1
    queue << [current, to]
  end
  colors = k - 2
end
puts ans.inject(1) { |res, num| res * num % MOD }
