from collections import deque

N = int(input())
link = [[] * N for _ in range(N)]

for i in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    link[a].append(b)
    link[b].append(a)

c = list(map(int, input().split()))
c = sorted(c, reverse=True)
sums = sum(c) - max(c)

q = deque([0])
d = [-1] * N

num = 0
while len(q) > 0:
    x = q.popleft()
    d[x] = c[num]
    num += 1
    for y in link[x]:
        if d[y] < 0:
            q.append(y)

print(sums)
print(*d) from collections import deque N = int(input()) N int(input()) int input() input [] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] * N [] N link = [[] * N for _ in range(N)] link [[] * N for _ in range(N)] for i in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    link[a].append(b)
    link[b].append(a) i range(N-1) range N-1 N 1 a, b = map(lambda x: int(x) - 1, input().split()) a map(lambda x: int(x) - 1, input().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x input().split() ().split () input split b link[a].append(b) [a].append [a] link a append b link[b].append(a) [b].append [b] link b append a c = list(map(int, input().split())) c list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c = sorted(c, reverse=True) c sorted(c, reverse=True) sorted c reverse=True reverse True sums = sum(c) - max(c) sums sum(c) - max(c) sum(c) sum c max(c) max c q = deque([0]) q deque([0]) deque [0] 0 d = [-1] * N d [-1] * N [-1] -1 N num = 0 num 0 while len(q) > 0:
    x = q.popleft()
    d[x] = c[num]
    num += 1
    for y in link[x]:
        if d[y] < 0:
            q.append(y) len(q) > 0 len(q) len q 0 x = q.popleft() x q.popleft() q.popleft q popleft d[x] = c[num] d[x] d x c[num] c num num += 1 num 1 for y in link[x]:
        if d[y] < 0:
            q.append(y) y link[x] link x if d[y] < 0:
            q.append(y) d[y] < 0 d[y] d y 0 q.append(y) q.append q append y print(sums) print sums print(*d) print *d d a, b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) a c = sorted(c, reverse=True) sorted(c, reverse=True) c num += 1 1 num d = [-1] * N [-1] * N d c = list(map(int, input().split())) list(map(int, input().split())) c x = q.popleft() q.popleft() x sums = sum(c) - max(c) sum(c) - max(c) sums N = int(input()) int(input()) N q = deque([0]) deque([0]) q link = [[] * N for _ in range(N)] [[] * N for _ in range(N)] link num = 0 0 num b = map(lambda x: int(x) - 1, input().split()) map(lambda x: int(x) - 1, input().split()) b
from collections import deque

N = int(input())
link = [[] * N for _ in range(N)]

for i in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    link[a].append(b)
    link[b].append(a)

c = list(map(int, input().split()))
c = sorted(c, reverse=True)
sums = sum(c) - max(c)

q = deque([0])
d = [-1] * N

num = 0
while len(q) > 0:
    x = q.popleft()
    d[x] = c[num]
    num += 1
    for y in link[x]:
        if d[y] < 0:
            q.append(y)

print(sums)
print(*d)