n=gets.to_i
l=[]
n.times do
  l << []
end
(n-1).times do
  a,b=gets.split.map(&:to_i)
  l[a-1] << b-1
  l[b-1] << a-1
end
c=gets.split.map(&:to_i).sort.reverse
s=[0]
v=[nil]*n
v[0]=c[0]
i=1
while s!=[]
  z=[]
  s.each do |ss|
    l[ss].each do |lss|
      if !v[lss]
        v[lss]=c[i]
        i+=1
        z << lss
      end
    end
  end
  s=z.dup
end
puts c[1,n-1].sum
puts v.join(" ")
