local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n, k = io.read("*n", "*n")
local t = {}
local colored = {}
for i = 1, n do
  t[i] = {}
  colored[i] = false
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  table.insert(t[a], b)
  table.insert(t[b], a)
end

local tasks = {}
local tasknum = 0
local done = 0

local function addtask(idx)
  if(not colored[idx]) then
    colored[idx] = true
    tasknum = tasknum + 1
    tasks[tasknum] = idx
  end
end

addtask(1)
local mod = 1000000007
local ret = k
while(done < tasknum) do
  done = done + 1
  local taskidx = done
  local idx = tasks[taskidx]
  local cnt = 0
  for i = 1, #t[idx] do
    local dstidx = t[idx][i]
    if not colored[dstidx] then
      cnt = cnt + 1
      addtask(dstidx)
    end
  end
  local col = k - 2
  if idx == 1 then
    col = k - 1
  end
  for i = 1, cnt do
    ret = (ret * col) % mod
    col = col - 1
  end
end
print(ret)
