n = gets.to_i
g = Array.new(n){ [] }
(n-1).times do
  a,b = gets.split.map(&:to_i)
  a -= 1; b -= 1
  g[a] << b
  g[b] << a
end

c = gets.split.map(&:to_i).sort.reverse.each
seen = Array.new(n, -1)
ans = 0

_, sv = g.each_with_index.max_by{|v,i|v.size}
que = [[sv,0]]
while que.size > 0
  v, pre = que.pop
  next if seen[v] != -1
  now = c.next
  seen[v] = now
  ans += pre < now ? pre : now
  g[v].each do |nv|
    que << [nv, now]
  end
end

puts ans
puts seen.join(" ")
