n = gets.to_i
ts = (n-1).times.map{gets.chomp.split.map(&:to_i)}
cs = gets.chomp.split.map(&:to_i).sort
ans_num = cs.inject(:+) - cs.max
ans_string = ""
graph = Array.new(n){Array.new(n,0)}
ts.each do |a,b|
  graph[a-1][b-1] += 1
  graph[b-1][a-1] += 1
end

nums = []
graph.each_with_index do |g,i|
  nums.push([i,g.inject(:+)])
end
nums.sort_by(&:last).reverse!
ans = Array.new(n)

nums.each do |num|
  ans[num[0]] = cs.pop
end

ans.each do |a|
  ans_string += "#{a}" + " "
end
 
puts ans_num
puts ans_string.chomp
