MOD = 1_000_000_007
N, K = gets.split.map(&:to_i)
arrs = (N - 1).times.map { gets.split.map(&:to_i) }
ways = {}
arrs.each do |from, to|
  ways[from] ||= []
  ways[from] << to
  ways[to] ||= []
  ways[to] << from
end
color_ways_count = Array.new(0)

counter = K
queue = ways[1].map {|i| [i, 1]}
visit = Hash.new(false)
visit[1] = true
ways[1].each {|i| visit[i] = true}
while !queue.empty?
  now_p, last_p = queue.shift
  counter *= K - (color_ways_count[last_p] || 0) - 1
  color_ways_count[now_p] = (color_ways_count[now_p] || 0) + 1
  color_ways_count[last_p] = (color_ways_count[last_p] || 0) + 1

  ways[now_p].each do |next_p|
    if !visit[next_p]
      visit[next_p] = true
      queue.push([next_p, now_p])
    end
  end
end

puts counter % MOD