# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
# delete line: Ctrl+Shift+k
# choose same words: Ctrl+Shift+l
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True)

R = lambda: list(map(int, input().split()))
input2 = sys.stdin.readline
R2 = lambda: list(map(int, input2().split()))

n = int(input())
ab = [R2() for i in range(n-1)]
c = R2()
c.sort(reverse=True)

# calculate
dic = {}
l = deque()
for a, b in ab:
    dic.setdefault(a, []).append(b)
    dic.setdefault(b, []).append(a)

m = sum(c) - max(c)
d = [-1] * n
l.extend(dic[1])
d[0] = c[0]
i = 1
while l:
    deq = l.popleft()
    if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1
print(m)
print(*d)
 import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 INF = 10 ** 18 INF 10 ** 18 10 18 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 from itertools import combinations, permutations from math import factorial def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result combinations_count if n - r < r: r = n - r
     n - r < r n - r n r r if r == 0: return 1
     r == 0 r 0 if r == 1: return n
     r == 1 r 1 n - r + k + 1 for k in range(r) for k in range(r) k range(r) range r for k in range(r) n - r + k + 1 n - r + k n - r n r k 1 numerator = [n - r + k + 1 for k in range(r)] numerator [n - r + k + 1 for k in range(r)] k + 1 for k in range(r) for k in range(r) k range(r) range r for k in range(r) k + 1 k 1 denominator = [k + 1 for k in range(r)] denominator [k + 1 for k in range(r)] for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
     p range(2,r+1) range 2 r+1 r 1 pivot = denominator[p - 1] pivot denominator[p - 1] denominator p - 1 p 1 if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
     pivot > 1 pivot 1 offset = (n - r) % p offset (n - r) % p n - r n r p for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
     k range(p-1,r,p) range p-1 p 1 r p numerator[k - offset] /= pivot numerator[k - offset] numerator k - offset k offset pivot denominator[k] /= pivot denominator[k] denominator k pivot result = 1 result 1 for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
     k range(r) range r if numerator[k] > 1:
            result *= int(numerator[k])
     numerator[k] > 1 numerator[k] numerator k 1 result *= int(numerator[k]) result int(numerator[k]) int numerator[k] numerator k return result result n n r r def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r) combination_with_repetition_count return combinations_count(n + r - 1, r) combinations_count(n + r - 1, r) combinations_count n + r - 1 n + r n r 1 r n n r r from collections import deque, Counter from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest from copy import deepcopy, copy from functools import reduce from fractions import gcd def gcds(numbers):
    return reduce(gcd, numbers) gcds return reduce(gcd, numbers) reduce(gcd, numbers) reduce gcd numbers numbers numbers def lcm(x, y):
    return (x * y) // gcd(x, y) lcm return (x * y) // gcd(x, y) (x * y) // gcd(x, y) x * y x y gcd(x, y) gcd x y x x y y def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True) lcms return reduce(lcm, numbers, 1) reduce(lcm, numbers, 1) reduce lcm numbers 1 numbers numbers R = lambda: list(map(int, input().split())) R lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split input2 = sys.stdin.readline input2 sys.stdin.readline sys.stdin sys stdin readline R2 = lambda: list(map(int, input2().split())) R2 lambda: list(map(int, input2().split())) list(map(int, input2().split())) list map(int, input2().split()) map int input2().split() ().split () input2 split n = int(input()) n int(input()) int input() input R2() for i in range(n-1) for i in range(n-1) i range(n-1) range n-1 n 1 for i in range(n-1) R2() R2 ab = [R2() for i in range(n-1)] ab [R2() for i in range(n-1)] c = R2() c R2() R2 c.sort(reverse=True) c.sort c sort reverse=True reverse True dic = {} dic {} l = deque() l deque() deque for a, b in ab:
    dic.setdefault(a, []).append(b)
    dic.setdefault(b, []).append(a) a b ab dic.setdefault(a, []).append(b) dic.setdefault(a, []).append dic.setdefault(a, []) dic.setdefault dic setdefault a [] append b dic.setdefault(b, []).append(a) dic.setdefault(b, []).append dic.setdefault(b, []) dic.setdefault dic setdefault b [] append a m = sum(c) - max(c) m sum(c) - max(c) sum(c) sum c max(c) max c d = [-1] * n d [-1] * n [-1] -1 n l.extend(dic[1]) l.extend l extend dic[1] dic 1 d[0] = c[0] d[0] d 0 c[0] c 0 i = 1 i 1 while l:
    deq = l.popleft()
    if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1 l deq = l.popleft() deq l.popleft() l.popleft l popleft if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1 d[deq-1] >= 0 d[deq-1] d deq-1 deq 1 0 if deq in dic:
            l.extend(dic[deq])
         deq in dic deq dic l.extend(dic[deq]) l.extend l extend dic[deq] dic deq d[deq-1] = c[i] d[deq-1] d deq-1 deq 1 c[i] c i i += 1 i 1 print(m) print m print(*d) print *d d def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r) def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r) combination_with_repetition_count input2 = sys.stdin.readline sys.stdin.readline input2 d = [-1] * n [-1] * n d def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result combinations_count m = sum(c) - max(c) sum(c) - max(c) m i = 1 1 i R2 = lambda: list(map(int, input2().split())) lambda: list(map(int, input2().split())) R2 l = deque() deque() l deq = l.popleft() l.popleft() deq def lcm(x, y):
    return (x * y) // gcd(x, y) def lcm(x, y):
    return (x * y) // gcd(x, y) lcm MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD dic = {} {} dic def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True) def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True) lcms c = R2() R2() c ab = [R2() for i in range(n-1)] [R2() for i in range(n-1)] ab i += 1 1 i R = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) R n = int(input()) int(input()) n INF = 10 ** 18 10 ** 18 INF def gcds(numbers):
    return reduce(gcd, numbers) def gcds(numbers):
    return reduce(gcd, numbers) gcds
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
# visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
# delete line: Ctrl+Shift+k
# choose same words: Ctrl+Shift+l
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from math import factorial
def combinations_count(n, r):
    # faster than the following code
    # def combinations_count(n, r):
    #     return factorial(n) // (factorial(n - r) * factorial(r))
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
    return result
def combination_with_repetition_count(n, r):
    return combinations_count(n + r - 1, r)
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers):
    return reduce(lcm, numbers, 1)
# set the inputs
    # open(0).read() is a convenient method:
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # R = lambda: map(int, input().split()) :it's fashionable, isn't it?
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

# n = 3
# ab = [[1, 3],[2, 3]]
# c = [1, 2, 3]
# c.sort(reverse=True)

R = lambda: list(map(int, input().split()))
input2 = sys.stdin.readline
R2 = lambda: list(map(int, input2().split()))

n = int(input())
ab = [R2() for i in range(n-1)]
c = R2()
c.sort(reverse=True)

# calculate
dic = {}
l = deque()
for a, b in ab:
    dic.setdefault(a, []).append(b)
    dic.setdefault(b, []).append(a)

m = sum(c) - max(c)
d = [-1] * n
l.extend(dic[1])
d[0] = c[0]
i = 1
while l:
    deq = l.popleft()
    if d[deq-1] >= 0:
        pass
    else:
        if deq in dic:
            l.extend(dic[deq])
        d[deq-1] = c[i]
        i += 1
print(m)
print(*d)

