N, K = gets.split(' ').map(&:to_i)
MOD = 10 ** 9 + 7
tree = Array.new(N + 1){Array.new}
(N - 1).times do
	a, b = gets.split(' ').map(&:to_i)
	tree[a].push(b)
	tree[b].push(a)
end

color = [1] + [K] * N
queue = [1]
while queue.size > 0
	pos = queue.shift
	if pos == 1
		remain = K - 1
	else
		remain = K - 2
	end
	tree[pos].each do |nxt|
		if color[nxt] == K && nxt != 1
			color[nxt] = remain
			remain -= 1
			queue.push(nxt)
		end
	end
end

puts color.inject{|a, b| (a * b) % MOD}