'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 search(index){
    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);
            search(ab[index][i]);
        }
    }
    return;
}

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

    if(n==1){
        c = parseInt(temp[1]);
        console.log(0);
        console.log(c);
        return;
    }
    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];
    search(1);

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