n, k = gets.chomp.split.map(&:to_i)
h = {}
if n == 1
  puts k
  exit
end
n.times do |i|
  h[i+1] = []
end
(n-1).times do
  a, b = gets.chomp.split.map(&:to_i)
  h[a] << b
  h[b] << a
end
s = 0
n.times do |i|
  if h[i+1].length == 1
    s = i+1
    break
  end
end
ss = []
sss = []
ss << s
c = 0
ans = 1
while sss.length < n
  c = ss.shift
  sss << c
  cnt = 0
  h[c].each do |hcc|
    if !sss.include?(hcc)
      ss << hcc
    end
  end
  h[c].each do |hcc|
    if sss.include?(hcc)
      cnt += 1
    end
    h[hcc].each do |hccc|
      if sss.include?(hccc) && hccc != c
        cnt += 1
      end
    end
  end
  ans *= (k - cnt)
  ans %= 1000000007
  if ans == 0
    puts 0
    exit
  end
end
puts ans
