def min(a, b)
  if a < b
    return a
  else
    return b
  end
end
a = gets.chomp.to_i
connect = {}
(a-1).times do
  _p, q = gets.chomp.split(' ').map(&:to_i)
  unless connect.keys.include? _p
    connect[_p] = [q]
  else
    connect[_p].push(q)
  end
end
c = gets.chomp.split(' ').map(&:to_i)
sum = 0
conb = []
c.combination(c.length) do |ary|
  tmp = 0
  connect.keys.each do |src|
    for i in 0..(connect[src].length - 1)
      dist = connect[src][i]
      tmp += min(ary[src-1], ary[dist-1])
    end
  end
  if tmp > sum
    sum = tmp
    conb = ary
  end
end
puts sum
conb.each do |c|
  print "#{c} "
end
print "\n"