n = gets.to_i
d = Array.new(n+1) {|i| [i, 0]}
edge = []

(n-1).times do
    edge << gets.split.map(&:to_i)
    d[edge[-1][0]][1] += 1
    d[edge[-1][1]][1] += 1
end

c = gets.split.map(&:to_i).sort
d.sort_by!{|i, x| x}

ans = Array.new(n+1)
n.times {|i| ans[d[i+1][0]] = c[i]}

m = edge.inject(0) {|r, (a, b)| r + [ans[a], ans[b]].min}
ans.shift
puts m, ans * " "