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

def dfs(now, par, s)
    return @k - s if @edge[now].empty? || (@edge[now].size == 1 && @edge[now][0] == par)

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

    return sum
end

M = 10 ** 9 + 7
puts dfs(1, 0, 0)