n, k = gets.split.map(&:to_i)
edge = Array.new(n+1){[]}
(n-1).times do
    a, b = gets.split.map(&:to_i)
    edge[a] << b
    edge[b] << a
end

mod = 10 ** 9 + 7

calc = Array.new(n+1, 1)
1.upto(n) {|i| calc[i] = calc[i-1] * (k-i-1) % mod}

ans = calc[edge[1].size - 1] * k * (k-1) % mod
que = edge[1].product([1])

while now = que.shift
    x, y = now
    ans = ans * calc[edge[x].size - 1] % mod
    que += (edge[x] - [y]).product([x])
end

puts ans