n = gets.to_i
adj = {}
(n - 1).times do
  a, b = gets.split(' ').map(&:to_i)
  adj[a] ||= {}
  adj[a][b] = 1
  adj[b] ||= {}
  adj[b][a] = 1
end
c = gets.split(' ').map(&:to_i).sort
sum = c[0...(n - 1)].inject(:+)

d = (0..n).map { nil }
v = (0..n).map { false }

s = [1]
v[1] = true
while !(s.empty?) do
  i = s.pop
  d[i] = c.pop
  adj[i].each_key do |j|
    unless v[j]
      v[j] = true
      s.push(j)
    end
  end
end

puts sum
puts d[1..n].join(' ')
