n,k = gets.chomp.split(" ").map(&:to_i)


degree = Array.new(n,0)
for i in 1..n-1
    a,b = gets.chomp.split(" ").map(&:to_i)
    degree[a-1] += 1
    degree[b-1] += 1
end
degree.sort!.reverse!
pro = [k-2]
for i in 1..degree.max
    pro.push(pro[i-1]*(k-2-i))
end
sum = k*(k-1)

for i in 1..n do
    if degree[i-1] <= 1
        break
    end
    sum *= pro[degree[i-1]-2]
end

p sum % (10**9 +7)
