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

edge = Array.new(n).map{Array.new}
for i in 1..n-1 do
    a,b = gets.chomp.split(" ").map(&:to_i)
    edge[a-1].push(b)
    edge[b-1].push(a)    
end
stack = [[1,0]]
sum = k
while ! stack.empty?
    tars = stack.shift
    tar = tars[0]
    last = tars[1]
    if last == 0
        cnt = 0
    else
        cnt = 1
    end
    for i in edge[tar-1]
        if i != last
            stack.push([i,tar])
            sum *= k-1-cnt
            sum %= 10**9 +7
            cnt += 1
        end
    end
end
p sum % (10**9 +7)