'use strict'

const INF = 900719925474099;
function mapint(temp){
    return temp.split(' ').map((v)=>parseInt(v));
}

let ab;
let c;
let ans;
let n;
let sum;

function Main(input){
    let temp = input.trim().split('\n');
    n = parseInt(temp[0]);

    ans = new Array(n+1).fill(0);

    ab = [...new Array(n+1)].map(()=>new Array(0));

    let ss = new Array(n+1);
    let t;
    for(let i=1;i<n;i++){
        t = mapint(temp[i]);
        ab[t[0]].push(t[1]);
        ab[t[1]].push(t[0]);
    }

    c = mapint(temp[n]);
    c.sort((a,b)=>a-b);

    sum = -c[n-1];
    
    let len = c.length;
    let index = 1;
    while(len > 0){
        if(ans[index] == 0){
            ans[index] = c.pop();
            sum += ans[index];
        }
        let l = ab[index].length;
        for(let i=0;i<l;i++){
            if(ans[ab[index][i]] == 0){
                //console.log('ab[index]:',ab[index],'index:',index,'i:',i,'sum:',sum);
                ans[ab[index][i]] = c.pop();
                sum += ans[ab[index][i]];
            }
        }
        index++;
        len = c.length
        //console.log(index,len);
    }

    console.log(sum);
    console.log(ans.join(' ').slice(2));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
