local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n = io.read("*n")
local at, bt = {}, {}
local c = {}
local ref = {}
for i = 1, n do
  ref[i] = {}
  ref[i].dst = {}
  ref[i].dstnum = 0
  ref[i].c = 0
  ref[i].reserved = false
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  at[i], bt[i] = a, b
  table.insert(ref[a].dst, b)
  table.insert(ref[b].dst, a)
  ref[a].dstnum, ref[b].dstnum = ref[a].dstnum + 1, ref[b].dstnum + 1
end
for i = 1, n do
  c[i] = io.read("*n")
end
table.sort(c)
local tasks = {}
local tasknum, done = 0, 0
local function addtask(idx)
  ref[idx].reserved = true
  table.insert(tasks, idx)
  tasknum = tasknum + 1
end
for i = 1, n do
  if #(ref[i].dst) == 1 then
    addtask(i)
  end
end
while done < tasknum do
  done = done + 1
  local idx = tasks[done]
  ref[idx].c = c[done]
  for i = 1, #(ref[idx].dst) do
    local dstidx = ref[idx].dst[i]
    if not ref[dstidx].reserved then
      ref[dstidx].dstnum = ref[dstidx].dstnum - 1
      if ref[dstidx].dstnum == 1 then
        addtask(dstidx)
      end
    end
  end
end

local sum = 0
for i = 1, n - 1 do
  sum = sum + mmi(ref[at[i]].c, ref[bt[i]].c)
end
print(sum)
io.write(ref[1].c)
for i = 2, n do
  io.write(" " .. ref[i].c)
end
io.write("\n")
