using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{
    static long N;
    static long[] C;
    static Point[] Points;
    static bool[] used;
    static long ans = 0;
    static void Main(string[] args)
    {

        //A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        N = long.Parse(Console.ReadLine());
        Points = new Point[N+1];
        used = new bool[N + 1];
        for (int i = 0; i <= N; i++)
        {
            Points[i] = new Point();
        }

        for (int i = 0; i < N - 1; i++)
        {
            var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var A = AB[0];
            var B = AB[1];

            Points[A].adj.Add(B);
            Points[A].count++;
            Points[B].adj.Add(A);
            Points[B].count++;
        }

        C = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        Array.Sort(C);
        Array.Reverse(C);

        var sp = 0L;
        for (int i = 1; i <= N; i++)
        {
            if(Points[i].count > Points[sp].count)
            {
                sp = i;
            }
        }

        WFS(sp);
        used = new bool[N + 1];
        WFS2(sp);
        var ans2 = new long[N];
        for (int i = 0; i < N; i++)
        {
            ans2[i] = Points[i + 1].point;
        }
        Console.WriteLine(ans);
        Console.WriteLine(String.Join(" ",ans2));
    }

    static void WFS2(long stp)
    {
        var que = new Queue<long>();
        que.Enqueue(stp);
        used[stp] = true;

        while(que.Count > 0)
        {
            var top = que.Dequeue();
            foreach (var item in Points[top].adj)
            {
                if (!used[item])
                {
                    que.Enqueue(item);
                    ans += Math.Min(Points[item].point, Points[top].point);
                    used[item] = true;
                }
            }
        }
    }

    static void WFS(long stp)
    {
        var pq = new PriorityQueue<Tuple<long,long>>();
        var now = 0;
        pq.Enqueue(new Tuple<long, long>(Points[stp].count, stp));
        used[stp] = true;
        while (pq.Count() > 0)
        {
            var top = pq.Dequeue();
            Points[top.Item2].point = C[now];
            now++;
            foreach (var item in Points[top.Item2].adj)
            {
                if (!used[item])
                {
                    pq.Enqueue(new Tuple<long, long>(Points[item].count, item));
                    used[item] = true;
                }
            }
        }
    }
}
public class Point
{
    public List<long> adj;
    public long count = 0;
    public long point = 0;
    public Point()
    {
        adj = new List<long>();
    }
}

public class PriorityQueue<T> : IEnumerable<T>
{
    private readonly List<T> _data = new List<T>();
    private readonly IComparer<T> _comparer;
    private readonly bool _isDescending;

    public PriorityQueue(IComparer<T> comparer, bool isDescending = true)
    {
        _comparer = comparer;
        _isDescending = isDescending;
    }

    public PriorityQueue(Comparison<T> comparison, bool isDescending = true)
        : this(Comparer<T>.Create(comparison), isDescending)
    {
    }

    public PriorityQueue(bool isDescending = true)
        : this(Comparer<T>.Default, isDescending)
    {
    }

    public void Enqueue(T item)
    {
        _data.Add(item);
        var childIndex = _data.Count - 1;
        while (childIndex > 0)
        {
            var parentIndex = (childIndex - 1) / 2;
            if (Compare(_data[childIndex], _data[parentIndex]) >= 0)
                break;
            Swap(childIndex, parentIndex);
            childIndex = parentIndex;
        }
    }

    public T Dequeue()
    {
        var lastIndex = _data.Count - 1;
        var firstItem = _data[0];
        _data[0] = _data[lastIndex];
        _data.RemoveAt(lastIndex--);
        var parentIndex = 0;
        while (true)
        {
            var childIndex = parentIndex * 2 + 1;
            if (childIndex > lastIndex)
                break;
            var rightChild = childIndex + 1;
            if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0)
                childIndex = rightChild;
            if (Compare(_data[parentIndex], _data[childIndex]) <= 0)
                break;
            Swap(parentIndex, childIndex);
            parentIndex = childIndex;
        }
        return firstItem;
    }

    public T Peek()
    {
        return _data[0];
    }

    private void Swap(int a, int b)
    {
        var tmp = _data[a];
        _data[a] = _data[b];
        _data[b] = tmp;
    }

    private int Compare(T a, T b)
    {
        return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b);
    }

    public int Count => _data.Count;

    public IEnumerator<T> GetEnumerator()
    {
        return _data.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
















Measured memory_bytes: 48480