import java.math.*
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val edges = mutableListOf<Pair<Int, Int>>()
    val adjacency = Array(N) { mutableListOf<Int>() }

    val nodeNum = IntArray(N)

    for (i in 1 until N) {
        val (x, y) = readInputLine().split(" ").map { it.toInt() - 1 }
        edges.add(Pair(x, y))
        adjacency[x].add(y)
        adjacency[y].add(x)
    }
    
    val cs = readInputLine().split(" ").map { it.toInt() }.sortedDescending()

    val queue = ArrayDeque<Int>()
    queue.add(0)
    
    for (c in cs) {
        val node = queue.poll()!!
        nodeNum[node] = c
        
        for (e in adjacency[node]) {
            if (nodeNum[e] == 0) {
                queue.add(e)
            }
        }
    }

    var ans = 0
    
    for (e in edges) {
        ans += Math.min(nodeNum[e.first], nodeNum[e.second])
    }
    
    println(ans)
    println(nodeNum.joinToString(" "))
}

fun readInputLine(): String {
    return readLine()!!
}
