MOD = 1_000_000_007
N, K = gets.split.map(&:to_i)
unless N == 1
  arrs = (N - 1).times.map { gets.split.map(&:to_i) }
  ways = Array.new([])
  arrs.each do |from, to|
    ways[from] ||= []
    ways[from] << to
    ways[to] ||= []
    ways[to] << from
  end
  color_ways_count = Array.new()
  (1..N).each { |i| color_ways_count[i] = 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 = (counter * (K - color_ways_count[last_p] - 1)) % MOD
    color_ways_count[now_p] = color_ways_count[now_p] + 1
    color_ways_count[last_p] = color_ways_count[last_p] + 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
else
  puts K
end