#!/usr/bin/env ruby

n = gets.to_i
sides = []

(n-1).times do
  side = gets.split(' ').map &:to_i
  sides << side
end
sides.sort!{|a,b| a[0] <=> b[0] }

scores = gets.split(' ').map &:to_i
scores.sort!{|a,b| b <=> a}
puts scores.inject(:+) - scores.first

queue = []

sides.each do |side|
  queue << side[0] unless queue.include? side[0]
  queue << side[1] unless queue.include? side[1]
end

q2 = []
queue.each do |i|
  q2 << [i, scores[i]]
end

q2.sort!{|a,b| a[0] <=> b[0] }

puts q2.map{|q| q[1]}.join(' ')

