require 'set'
mod = 1000000007
str = gets.split
N,K = str[0].to_i, str[1].to_i
r = Array.new(N+1){Set.new}
s = Set.new
t = Array.new(0)
u = Set.new
empty = Set.new
for x in 1...N do
    str = gets.split
    a,b = str[0].to_i, str[1].to_i
    r[a].add(b)
    r[b].add(a)
end

s.add(1)
now = 1
answer = K
while true
   if (r[now]-s).size > 0
        (r[now]-s).each do |val|
            t.push(val)
        end
   end
   if t.size > 0
       now = t.pop
   else
       puts answer
       exit
   end
   (r[now]&s).each do |val|
        u = empty & empty
        u.add(val)
        answer = answer * (K-((r[val]+u)&s).size) % mod
   end
   s.add(now)
end