import java.util.Scanner


object Main {


  case class Edge(a: Int, b: Int)

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val edges = IndexedSeq.fill(n - 1) {
      //0-origin
      val a = sc.nextInt() - 1
      val b = sc.nextInt() - 1
      Edge(a, b)
    }
    val c = IndexedSeq.fill(n)(sc.nextInt())
    (n, edges, c)
  }

  def solve(n: Int, edges: IndexedSeq[Edge], c: IndexedSeq[Int]): Unit = {
    val degree = Array.fill(n)(0)
    for (edge <- edges) {
      degree(edge.a) += 1
      degree(edge.b) += 1
    }
    val order = (0 until n).sortBy(degree(_))
    val sortedC = c.sorted
    val result2 = Array.fill(n)(-111)
    for(i <- 0 until n){
      result2(order(i)) = sortedC(i)
    }
    val result1 = edges.map(edge => math.min(result2(edge.a), result2(edge.b))).sum
    println(result1)
    println(result2.mkString(" "))
  }

  def main(args: Array[String]): Unit = {
    val (n, edges, c) = read()
    solve(n, edges, c)
  }
}
