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

cs.sort!

edges = []
eedges = []
(n+1).times {
  edges << []
  eedges << []
}
#p edges
abs.each { |ab|
  edges[ab[0]] << ab[1]
  edges[ab[1]] << ab[0]
}

act = []
edges.each_with_index { |v,i|
  if v.size == 1
    act << i
  end
}

d = []
csi = 0
while act.size > 0
  next_act = []
  #p act
  #p edges
  #p eedges
  act.each { |i|
    d[i] = cs[csi]
    csi += 1
    if edges[i].size - eedges[i].size > 0
      j = (edges[i] - eedges[i]).first
      #p j
      #edges[j].delete(i)
      eedges[j] << i
      if (edges[j].size - eedges[j].size == 1)
        next_act << j
      end
    end
  }
  act = next_act
end
#p d

def min(x,y)
  return x > y ? y : x
end
sum = 0
abs.each { |ab|
  sum += min(d[ab[0]],d[ab[1]])
}

puts sum
d.shift
puts d.join(" ")
