Public Class Compiler
    Const M As Integer = 1000000007
    Shared Sub Main()
        Dim nk As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        Dim n As Integer = nk(0)    ' 頂点の数
        Dim k As Integer = nk(1)    ' 色の数
        Dim x(0 To n - 1) As Integer
        For i As Integer = 0 To n - 2
            Dim ab() As Integer = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
            x(ab(0) - 1) += 1
            x(ab(1) - 1) += 1
        Next
        Dim output As Long = Npr(k, x(0) + 1)
        For i As Integer = 1 To n - 1
            output = (output * Npr(k - 2, x(i) - 1)) Mod M
        Next
        Console.WriteLine(output.ToString())
    End Sub
    
    Shared Function Npr(n As Integer, r As Integer) As Long
        If n < r Then Return 0
        Dim result As Long = 1
        For i As Integer = 0 To r - 1
            result = (result * (n - i)) Mod M
        Next
        Return result
    End Function
End Class