using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private struct Pair { public long x, y; public Pair(long x, long y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        Node[] nodes = new Node[N];
        for (int i = 0; i < N; i++) nodes[i] = new Node(i);
        int[] a = new int[N - 1];
        int[] b = new int[N - 1];
        for (int i = 0; i < N - 1; i++)
        {
            a[i] = NextInt() - 1;
            b[i] = NextInt() - 1;
            nodes[a[i]].relate.Add(b[i]);
            nodes[b[i]].relate.Add(a[i]);
            nodes[a[i]].rel_c++;
            nodes[b[i]].rel_c++;
        }
        List<int> c = LineInt().OrderBy(v => v).ToList();

        Queue<Node> Q = new Queue<Node>();
        //関わりが1以下なら葉
        for (int i = 0; i < N; i++)
            if (nodes[i].relate.Count() <= 1) Q.Enqueue(nodes[i]);

        int x = 0;
        while (x < N)
        {
            Queue<Node> nextQ = new Queue<Node>();
            while (Q.Count() != 0)
            {
                var n = Q.Dequeue();
                if (n.visit) continue;
                n.visit = true;
                n.cost = c[x];
                x++;
                foreach (var to in n.relate)
                {
                    nodes[to].rel_c--;
                    //新たに葉になる場合
                    if (!nodes[to].visit && nodes[to].rel_c <= 1) nextQ.Enqueue(nodes[to]);
                }

            }
            Q = nextQ;
        }
        long M = 0;
        for (int i = 0; i < N - 1; i++) M += Math.Min(nodes[a[i]].cost, nodes[b[i]].cost);
        Console.WriteLine(M);
        for (int i = 0; i < N; i++)
            Console.Write(nodes[i].cost + " ");
        Console.WriteLine();

    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
public class Node
{
    public List<int> relate = new List<int>();
    public int rel_c = 0;
    public int name = 0;
    public bool visit = false;
    public long cost = 0;
    public Node(int name) { this.name = name; }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 22460