--https://www.lua.org/pil/11.4.html
local List = {}
function List.new ()
  return {first = 0, last = -1}
end

function List.pushleft (list, value)
  local first = list.first - 1
  list.first = first
  list[first] = value
end

function List.pushright (list, value)
  local last = list.last + 1
  list.last = last
  list[last] = value
end

function List.popleft (list)
  local first = list.first
  if first > list.last then return false end
  local value = list[first]
  list[first] = nil
  list.first = first + 1
  return value
end

function List.popright (list)
  local last = list.last
  if list.first > last then return false end
  local value = list[last]
  list[last] = nil
  list.last = last - 1
  return value
end

--------------------------------------------------------

local n,k=io.read("*n","*n")
local edge={}
for i=1,n do
    edge[i]={}
end
for i=1,n-1 do
    local a,b=io.read("*n","*n")
    edge[a][b]=false
    edge[b][a]=false
end

local pattern=k
local stack=List.new()
List.pushright(stack,1)

while true do
    local a=List.popright(stack)
    if not a then
        break 
    end
    local available_colors=k-1
    if a>1 then
        available_colors=available_colors-1
    end
    for b,_ in pairs(edge[a]) do
        if not edge[a][b] then
            edge[a][b]=true
            edge[b][a]=true
            List.pushright(stack,b)
            pattern=pattern*available_colors%1000000007
            available_colors=available_colors-1
        end
    end
end
print(pattern)