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

M = 10 ** 9 + 7

def dfs(now, par, s)
    sum = @k - s
    if !@edge[now].empty? && @edge[now] != [par]
        i = par == 0 ? 1 : 2
        @edge[now].each do |x|
            next if x == par
            sum = sum * dfs(x, now, i) % M
            i += 1
        end
    end

    sum
end

puts n == 1 ? @k : dfs(n/2, 0, 0)