N = int(input())
import collections

Ls = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1)

Cs = sorted(map(int, input().split()))
print(sum(Cs) - max(Cs))

sw = [-1] * N
stk = collections.deque([0])
while len(stk) > 0:
    crN = stk.popleft()
    if sw[crN] < 0:
        sw[crN] = Cs.pop()
        for l in Ls[crN]:
            stk.append(l)

print(*sw) N = int(input()) N int(input()) int input() input import collections collections [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] Ls = [[] for _ in range(N)] Ls [[] for _ in range(N)] for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1) _ range(N - 1) range N - 1 N 1 a, b = map(int, input().split()) a map(int, input().split()) map int input().split() ().split () input split b Ls[a - 1].append(b - 1) [a - 1].append [a - 1] Ls a - 1 a 1 append b - 1 b 1 Ls[b - 1].append(a - 1) [b - 1].append [b - 1] Ls b - 1 b 1 append a - 1 a 1 Cs = sorted(map(int, input().split())) Cs sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split print(sum(Cs) - max(Cs)) print sum(Cs) - max(Cs) sum(Cs) sum Cs max(Cs) max Cs sw = [-1] * N sw [-1] * N [-1] -1 N stk = collections.deque([0]) stk collections.deque([0]) collections.deque collections deque [0] 0 while len(stk) > 0:
    crN = stk.popleft()
    if sw[crN] < 0:
        sw[crN] = Cs.pop()
        for l in Ls[crN]:
            stk.append(l) len(stk) > 0 len(stk) len stk 0 crN = stk.popleft() crN stk.popleft() stk.popleft stk popleft if sw[crN] < 0:
        sw[crN] = Cs.pop()
        for l in Ls[crN]:
            stk.append(l) sw[crN] < 0 sw[crN] sw crN 0 sw[crN] = Cs.pop() sw[crN] sw crN Cs.pop() Cs.pop Cs pop for l in Ls[crN]:
            stk.append(l) l Ls[crN] Ls crN stk.append(l) stk.append stk append l print(*sw) print *sw sw Ls = [[] for _ in range(N)] [[] for _ in range(N)] Ls stk = collections.deque([0]) collections.deque([0]) stk a, b = map(int, input().split()) map(int, input().split()) a sw = [-1] * N [-1] * N sw Cs = sorted(map(int, input().split())) sorted(map(int, input().split())) Cs N = int(input()) int(input()) N b = map(int, input().split()) map(int, input().split()) b crN = stk.popleft() stk.popleft() crN
N = int(input())
import collections

Ls = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    Ls[a - 1].append(b - 1)
    Ls[b - 1].append(a - 1)

Cs = sorted(map(int, input().split()))
print(sum(Cs) - max(Cs))

sw = [-1] * N
stk = collections.deque([0])
while len(stk) > 0:
    crN = stk.popleft()
    if sw[crN] < 0:
        sw[crN] = Cs.pop()
        for l in Ls[crN]:
            stk.append(l)

print(*sw)