MOD = 10 ** 9 + 7
N, K = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  a, b = gets.split.map { |a| a.to_i - 1 }

  E[a] << b
  E[b] << a
end

def dfs(cur = 0, from = -1)
  can_use_color_cnt = (from == -1) ? K - 1 : K - 2

  if E[cur].size > K
    0
  else
    res = 1

    E[cur].each do |u|
      next if u == from

      res = res * can_use_color_cnt % MOD
      can_use_color_cnt -= 1
    end

    E[cur].each do |u|
      next if u == from

      res = res * dfs(u, cur) % MOD
    end

    res
  end
end

ans = K * dfs % MOD

puts ans
