n = gets.to_i
c =[]


edges = Hash.new{|h,k| h[k] = []}
a = []
b = []

(n-1).times do |i|
  a[i], b[i] = gets.split(" ").map(&:to_i)
  a[i] -= 1
  b[i] -= 1
  edges[a[i]] << b[i]
  edges[b[i]] << a[i]
end

c = gets.split(" ").map(&:to_i)
c.sort!.reverse!

edges = edges.sort_by{|a,b| -b.size}

nodes = Array.new(n)

n.times do |i|
  nodes[edges[i][0]] = c[i]
end

ans = 0

(n-1).times do |i|
  tmp = nodes[a[i]]
  tmp = nodes[b[i]] if tmp > nodes[b[i]]
  ans += tmp
end

puts ans
puts nodes.join(" ")
