lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

access = []
for i in 1..N do
  access[i-1] = []
end
for i in 1..N-1 do
  from = lines[i][0]
  to = lines[i][1]
  access[from-1].push(to)
  access[to-1].push(from)
end

c = lines[N].sort.reverse

visited = []
for i in 1..N do
  visited[i-1] = false
end

target = [1]
ans = []
num = 0
while target != [] do
  next_target = []
  target.each do |i|
    ans.push(c[num])
    num += 1
    visited[i-1] = true
    access[i-1].each do |j|
      if visited[j-1] == false then
        next_target.push(j)
      end
    end
  end
  target = next_target
end
  
num_ans = 0
for i in 1..N-1 do
  num_ans += c[i]
end
  
puts num_ans
for i in 1..N do
  print ans[i-1]
  if i != N then
    print " "
  end
end