n = gets.to_i
abs = []
(n-1).times {
  abs << gets.split.map {|x| x.to_i}
}
cs = gets.split.map {|x| x.to_i}

ws = Array.new(n+1,0)
abs.each { |ab|
  ws[ab[0]] += 1
  ws[ab[1]] += 1
}

ws2 = []
ws.each_with_index { |v,i|
  ws2 << [i,v]
}

ws2.sort! {|x,y| x[1] <=> y[1]}
cs.sort!

ws2.shift
#p ws2
#p cs
d = []
n.times { |i|
  d[ws2[i][0]] = cs[i]
}

def min(x,y)
  return x > y ? y : x
end

#p d
sum = 0
abs.each { |ab|
  sum += min(d[ab[0]], d[ab[1]])
}
puts sum
d.shift
puts d.join(" ")
