N=gets.to_i
es = {}
(N-1).times do
  a,b = gets.split.map(&:to_i)
  es[a] ||= []
  es[a] << b
  es[b] ||= []
  es[b] << a
end
cs = gets.split.map(&:to_i).sort

arr = Array.new(N+1,0)

arr[1] = cs.pop
q = es[1]
ret = 0
until q.empty?
  node = q.shift
  next if arr[node] != 0
  arr[node] = cs.pop
  ret += arr[node]
  q += es[node]
end

p ret
puts arr[1..-1].join(' ')
