import java.util.*
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ab =Array(n-1){ readLine()!!.split(" ").map { it->it.toInt()-1 }}
    val c =readLine()!!.split(" ").map { it.toInt() }.sortedBy { -it }.toIntArray()
    val es = Array(n){ArrayList<Int>()}
    ab.forEach {
        es[it[0]].add(it[1])
        es[it[1]].add(it[0])
    }
    val visit = BooleanArray(n){false}
    println(c.sum()-c.max()!!)
    val result = IntArray(n){0}
    val queue = ArrayDeque<Int>()
    visit[0]=true
    queue.add(0)
    var cursor = 0
    while (!queue.isEmpty()){
        val node = queue.pop()
        es[node].forEach{
            if(!visit[it]){
                visit[it]=true
                queue.add(it)
            }
        }
        result[node]=c[cursor]
        cursor+=1
    }
    println(result.joinToString(" "))
}
