N, K = gets.split.map(&:to_i)
tree = Array.new(N,0)
(N-1).times do |i|
  a,b = gets.split.map(&:to_i)
  tree[a-1] += 1
  tree[b-1] += 1
end
mod = 10**9 + 7
ans = 1

def perm(n,k)
  return 1 if k > n || k == 0
  (n - k + 1..n).inject(:*)
end

for i in 0...N
  if i == 0
    ans *= perm(K,tree[i]+1)
    ans %= mod
  else
    ans *= perm(K-2,tree[i]-1)
    ans %= mod
  end
end
puts ans