"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;
function PriorityQueue(t,i){this._pq=[null].concat(t),this._cf=i||function(t,i){return t>i};for(let t=Math.floor(this._pq.length/2);t>=1;t--)this._maxHeapify(t)}PriorityQueue.prototype._parent=function(t){return Math.floor(t/2)},PriorityQueue.prototype._left=function(t){return 2*t},PriorityQueue.prototype._right=function(t){return 2*t+1},PriorityQueue.prototype._maxHeapify=function(t){(function t(i){let e=this._left(i),p=this._right(i),r=i;if(e<this._pq.length&&this._cf(this._pq[e],this._pq[i])&&(r=e),p<this._pq.length&&this._cf(this._pq[p],this._pq[r])&&(r=p),r!==i){let e=this._pq[i];this._pq[i]=this._pq[r],this._pq[r]=e,t.call(this,r)}}).call(this,t)},PriorityQueue.prototype.maximum=function(){return this._pq[1]},PriorityQueue.prototype.extractMax=function(){if(this._pq.length<=1)return;let t=this._pq[1];return this._pq[1]=this._pq[this._pq.length-1],this._pq.pop(),this._maxHeapify(1),t},PriorityQueue.prototype.increaseKey=function(t,i){let e=t;if(!this._pq[e]||this._cf(i,this._pq[e]))for(this._pq[e]=i;e>1&&!this._cf(this._pq[this._parent(e)],this._pq[e]);){let t=this._pq[e];this._pq[e]=this._pq[this._parent(e)],this._pq[this._parent(e)]=t,e=this._parent(e)}},PriorityQueue.prototype.insert=function(t){this._pq.push(null),this.increaseKey(this._pq.length-1,t)},PriorityQueue.prototype.size=function(t){return this._pq.length-1};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < n - 1; i++) {
    var a = o.a();
    var b = o.a();
    adj[a].push(b);
    adj[b].push(a);
  }

  var c = o.l();
  c.sort((a, b) => b - a);

  var maxLength = 0;
  var maxNode;
  for (var i = 1; i <= n; i++) {
    if (adj[i].length > maxLength) {
      maxLength = adj[i].length;
      maxNode = i;
    }
  }

  var color = [];
  var mark = [];
  var currentCIndex = 0;
  var pq = new PriorityQueue([], (a, b) => a.size > b.size);
  pq.insert({ value: maxNode, size: adj[maxNode].length });
  color[maxNode] = 1;

  while (pq.size() > 0) {
    var v = pq.extractMax();
    mark[v.value] = c[currentCIndex];
    currentCIndex += 1;

    adj[v.value].forEach(u => {
      if (color[u] === undefined) {
        color[u] = 1;
        pq.insert({value: u, size: adj[u].length});
      }
    });
  }

  var total = c.slice(1).reduce((a, b) => a + b);
  console.log(total);
  console.log(mark.slice(1).join(" "));
}

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