import java.util.*

fun main(args: Array<String>) {
    val mod = 1000000007
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val edge = Array(n) {
        emptyList<Int>().toMutableList()
    }
    for (i in 1 until n) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        edge[a - 1].add(b - 1)
        edge[b - 1].add(a - 1)
    }
    val score = Array(n) { (-n - 1).toLong() }
    // (Point, (dist=1, dist=2))
    val que = LinkedList<Pair<Int, Pair<Long, Long>>>()
    que.add(Pair(0, Pair(0L, 0L)))
    while (que.isNotEmpty()) {
        val (point, pair) = que.remove()!!
        score[point] = k - (pair.first + pair.second)
        var index = 0
        edge[point].forEach {
            if (score[it] < -n) {
                que.add(Pair(it, Pair(1L, pair.first + index)))
                index++
            }
        }
    }
    println(score.reduce { acc, i -> acc * i % mod })
}
