val P = 1000000007L

data class Edge(val from: Int, val to: Int)

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val graph = Array(n, { mutableListOf<Edge>() })
    repeat(n - 1) {
        val (aRaw, bRaw) = readLine()!!.split(" ").map { it.toInt() }
        val a = aRaw - 1
        val b = bRaw - 1
        graph[a].add(Edge(a, b))
        graph[b].add(Edge(b, a))
    }

    fun solve(v: Int, parent: Int, depth: Int): Long {
        if (graph[v].size == 0) return 1L
        val numChildren = graph[v].size - if (depth > 0) 1 else 0
        val numColors = k - 1 - if (depth > 0) 1 else 0
        if (numColors < numChildren) return 0L
        var ans = 1L
        for (i in 0 until numChildren) {
            ans *= numColors - i
            ans %= P
        }
        for (e in graph[v]) {
            if (e.to == parent) continue
            ans *= solve(e.to, v, depth + 1)
            ans %= P
        }
        return ans
    }
    println(solve(0, -1, 0) * k % P)
}