N = gets.to_i
ab_list = (N - 1).times.map { gets.split.map(&:to_i) }
c_list = gets.split.map(&:to_i).sort_by { |n| -n }

table = {}
ab_list.each do |(a, b)|
  table[a] ||= 0
  table[a] += 1
  table[b] ||= 0
  table[b] += 1
end

vc_list = table.sort_by do |(_, v)|
  -v
end

ret_list = Array.new(N)
vc_list.each do |(v, _)|
  ret_list[v - 1] = c_list.shift
end

ans = 0
ab_list.each do |(a, b)|
  ans += [ret_list[a - 1], ret_list[b - 1]].min
end
puts ans
puts "#{ret_list.join(' ')}"
