function Main(input) {
	input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	let N = parseInt(input[0][0], 10);
	let graph = Array.from({length: N}, () => []);
	let line;
	for  (let i = 0; i < N - 1; i++){
		line = input[i + 1].map(e => parseInt(e, 10));
		graph[line[0] - 1].push(line[1] - 1);
		graph[line[1] - 1].push(line[0] - 1);
	}
	let v_c = input[N].map(e => parseInt(e, 10));
	v_c.sort((a, b) => a - b);
	let tmp = v_c.pop();
	var sum  = function(arr) {
		var sum = 0;
		arr.forEach(function(elm) {
			sum += elm;
		});
		return sum;
	};
	console.log(sum(v_c));
	v_c.push(tmp);
	v_ans = [];
	let j = 0;
	while (j < N - 1){
		for  (let i = 0; i < N; i++){
			if (graph[i].length === 1) {
				// console.log("ij", i, j);
				tmp = graph[i].pop();
				graph[tmp].splice(graph[tmp].indexOf(i), 1);
				v_ans[i] = v_c[j];
				j ++;
				// console.log(v_ans);
				// console.log(graph);
			}
		}
	}

	for (let i = 0; i < N; i++){
		if (v_ans[i] == null) {v_ans[i] = v_c[N - 1]; break;}
	}
	
	console.log(v_ans.join(" "));

}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


