# https://atcoder.jp/contests/abc133/tasks/abc133_e
MOD = (10**9) + 7
N, K = gets.split.map(&:to_i)
ab = []
tree = Array.new(N) {Array.new}
already_used = Array.new(N)
ss = []
(N-1).times do
  ab = gets.split.map(&:to_i)
  tree[ab[0]-1] << ab[1]-1
  tree[ab[1]-1] << ab[0]-1
end

# nPr = (n-r+1)..n
def permutate(nnn, rrr)
  ((nnn - rrr + 1)..nnn).reduce(1) { |i, obj| obj = (obj * i)%MOD }
end

tree.map!(&:sort)

ans = 1
# 親ノードの組み合わせ
ans *= (K * permutate(K-1, tree[0].size))%MOD
already_used[0] = true
queue = tree[0].map(&:itself)
while curr_node = queue.shift
  next if already_used[curr_node]
  already_used[curr_node] = true

  valid_node_count = 0
  tree[curr_node].each do |i|
    next if already_used[i]
    queue << i
    valid_node_count += 1
  end
  ans = (ans * permutate(K-2, valid_node_count))%MOD
end

puts ans
