console.log((args=>{
  const [[N],...tmp] = args.trim().split('\n').map(r=>r.split(' ').map(v=>v|0));
  const c = tmp[N-1].sort((a,b)=>a-b);
  const G = Array.from({length:N},_=>[]);
  for ( let i = 0; i < N-1; i++ ) {
    const [a,b] = tmp[i];
    G[a-1].push(b-1);
    G[b-1].push(a-1);
  }
  let stack = [0], _stack = [];
  const d = Array(N).fill(0);
  d[0] = c.pop();
  const M = c.reduce((a,b)=>a+b);
  while( stack.length ) {
    const v = stack.pop();
    for ( const n of G[v] ) {
      if ( d[n] ) continue;
      d[n] = c.pop();
      _stack.push( n );
    }
    if ( stack.length === 0 ) [stack,_stack] = [_stack,[]];
  }
  return M + '\n' + d.join` `;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));
