import java.util.ArrayDeque

fun main(args: Array<String>) {
    val mod = 1000000007L
    val (N, K) = readInputLine().split(" ").let { Pair(it[0].toInt(), it[1].toLong()) }

    val next = Array(N + 1) { mutableListOf<Int>() }

    for (i in 1 until N) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() }
        next[a].add(b)
        next[b].add(a)
    }

    val checked = BooleanArray(N + 1)
    val queue = ArrayDeque<Int>(N)
    checked[1] = true

    var ans = K

    for (i in 1..next[1].size) {
        ans *= K - i
        ans %= mod
    }

    for (node in next[1]) {
        queue.add(node)
        checked[node] = true
    }

    while (queue.isNotEmpty()) {
        val s = queue.poll()!!

        var cnt = 1

        for (node in next[s]) {
            if (!checked[node]) {
                ans *= K - cnt - 1
                ans %= mod
                cnt++
                queue.add(node)
                checked[node] = true
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
