n = gets.to_i
a = Array.new(n-1)
b = Array.new(n-1)
for i in 0..(n-2)
  a[i], b[i] = gets.split.map(&:to_i)
end
c = gets.split.map(&:to_i)

brs = Array.new(n).map{Array.new(2)}
ps = Array.new(n)
for i in 0..(n-1)
  brs[i][0] = i
  brs[i][1] = 0
end
for i in 0..(n-2)
  brs[a[i] - 1][1] += 1
  brs[b[i] - 1][1] += 1 if a[i] != b[i]
end
c.sort!{|a, b| b <=> a}
brs.sort!{|a, b| b[1] <=> a[1]}
for i in 0..(n-1)
  ps[brs[i][0]] = c[i]
end

sum = 0
for i in 0..(n-2)
  sum += [ps[a[i] - 1], ps[b[i] - 1]].min
end
puts sum
puts ps.join(' ')