Module Program
    Sub Main()
        Dim taskE As TaskE = New TaskE()
    End Sub
End Module

Public Class TaskE
    Const P As Integer = 1000000007
    Public Sub New()
        Dim inputs As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        Dim n As Integer = inputs(0)    ' 頂点の数
        Dim k As Integer = inputs(1)    ' 色の数
        Dim x(0 To n - 1) As Integer    ' 各頂点(頂点0, 頂点1, ... , 頂点n-1)の辺の数
        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
        ' 頂点0と子の色の塗り分け方 Npr(k, x(0) + 1)
        Dim output As Long = Npr(k, x(0) + 1)
        For i As Integer = 1 To n - 1
            ' 頂点iの子の色の塗り分け方 Npr(k -2, x(i) - 1)
            output = (output * Npr(k - 2, x(i) - 1)) Mod P
        Next
        Console.WriteLine(output.ToString())
    End Sub
    
    Private Function Npr(n As Integer, r As Integer) As Integer
        If n < r Then Return 0
        Dim result As Integer = 1
        ' nPr = n! / (n - r)! = n * (n - 1) * ... * (n - r + 1)
        For i As Integer = 0 To r - 1
            result = (result * (n - i)) Mod P
        Next
        Return result
    End Function
End Class