import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val n = in.readInt

  val node = Array.ofDim[Int](n+1)
  val graph = Array.fill(n+1)(mu.ListBuffer.empty[Int])

  val edges = Iterator.continually(in.readLine)
    .take(n-1)
    .map(_.split(" ").map(_.toInt))
    .toArray

  val c = in.readLine.split(" ").map(_.toInt).sorted(Ordering[Int].reverse)

  edges.foreach { e =>
    e(1) +=: graph(e(0))
    e(0) +=: graph(e(1))
  }

  val visited = Array.ofDim[Boolean](n+1)
  val ite = c.iterator

  def dfs(v:Int):Unit = {
    if(visited(v)) return
    else {
      visited(v) = true
      node(v) = ite.next
      for(nx <- graph(v)) {
        dfs(nx)
      }
    }
  }
  dfs(1)

  val ans = (0 until n-1)./:(0)((acc, i) => {
    acc + ( node(edges(i)(0)) min node(edges(i)(1)) )
  })

  println(ans)
  println(node.tail.mkString(" "))
}