--http://www.nct9.ne.jp/m_hiroi/light/lua07.html
Stack = {}

function Stack.new()
  local obj = { buff = {} }
  return setmetatable(obj, {__index = Stack})
end

function Stack:push(x)
  table.insert(self.buff, x)
end

function Stack:pop()
  return table.remove(self.buff)
end

function Stack:top()
  return self.buff[#self.buff]
end

function Stack:isEmpty()
  return #self.buff == 0
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=Stack.new()
stack:push(1)

while not stack:isEmpty() do
    local not_painted=0
    local a=stack:pop()
    for b,_ in pairs(edge[a]) do
        if not edge[a][b] then
            edge[a][b]=true
            edge[b][a]=true
            stack:push(b)
            not_painted=not_painted+1
        end
    end
    local available_colors
    if a==1 then
        available_colors=k-1
    else
        available_colors=k-2
    end
    for i=1,not_painted do
        pattern=pattern*available_colors%1000000007
        available_colors=available_colors-1
    end
end
print(pattern)